Skip to content

Commit fd643e8

Browse files
authored
Merge pull request #14 from magento-commerce/imported-magento-magento-coding-standard-211
[Imported] #210: Fixed HtmlDirectiveSniff.php from causing the Fatal Error for c…
2 parents 8deeced + 1a0f854 commit fd643e8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Magento2/Sniffs/Html/HtmlDirectiveSniff.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Magento2\Sniffs\Html;
1010

11-
use Magento\Framework\Filter\Template;
1211
use PHP_CodeSniffer\Sniffs\Sniff;
1312
use PHP_CodeSniffer\Files\File;
1413

@@ -17,6 +16,11 @@
1716
*/
1817
class HtmlDirectiveSniff implements Sniff
1918
{
19+
const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si';
20+
const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si';
21+
const LOOP_PATTERN = '/{{for(?P<loopItem>.*? )(in)(?P<loopData>.*?)}}(?P<loopBody>.*?){{\/for}}/si';
22+
const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}(?:(.*?)(?:{{\/(?:\\1)}}))?/si';
23+
2024
/**
2125
* @var array
2226
*/
@@ -73,7 +77,7 @@ public function process(File $phpcsFile, $stackPtr)
7377
*/
7478
private function processIfDirectives(string $html, File $phpcsFile): string
7579
{
76-
if (preg_match_all(Template::CONSTRUCTION_IF_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
80+
if (preg_match_all(self::CONSTRUCTION_IF_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
7781
foreach ($constructions as $construction) {
7882
// validate {{if <var>}}
7983
$this->validateVariableUsage($phpcsFile, $construction[1]);
@@ -93,7 +97,7 @@ private function processIfDirectives(string $html, File $phpcsFile): string
9397
*/
9498
private function processDependDirectives(string $html, File $phpcsFile): string
9599
{
96-
if (preg_match_all(Template::CONSTRUCTION_DEPEND_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
100+
if (preg_match_all(self::CONSTRUCTION_DEPEND_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
97101
foreach ($constructions as $construction) {
98102
// validate {{depend <var>}}
99103
$this->validateVariableUsage($phpcsFile, $construction[1]);
@@ -113,7 +117,7 @@ private function processDependDirectives(string $html, File $phpcsFile): string
113117
*/
114118
private function processForDirectives(string $html, File $phpcsFile): string
115119
{
116-
if (preg_match_all(Template::LOOP_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
120+
if (preg_match_all(self::LOOP_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
117121
foreach ($constructions as $construction) {
118122
// validate {{for in <var>}}
119123
$this->validateVariableUsage($phpcsFile, $construction['loopData']);
@@ -133,7 +137,7 @@ private function processForDirectives(string $html, File $phpcsFile): string
133137
*/
134138
private function processVarDirectivesAndParams(string $html, File $phpcsFile): string
135139
{
136-
if (preg_match_all(Template::CONSTRUCTION_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
140+
if (preg_match_all(self::CONSTRUCTION_PATTERN, $html, $constructions, PREG_SET_ORDER)) {
137141
foreach ($constructions as $construction) {
138142
if (empty($construction[2])) {
139143
continue;

0 commit comments

Comments
 (0)