8
8
9
9
namespace Magento2 \Sniffs \Html ;
10
10
11
- use Magento \Framework \Filter \Template ;
12
11
use PHP_CodeSniffer \Sniffs \Sniff ;
13
12
use PHP_CodeSniffer \Files \File ;
14
13
17
16
*/
18
17
class HtmlDirectiveSniff implements Sniff
19
18
{
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
+
20
24
/**
21
25
* @var array
22
26
*/
@@ -73,7 +77,7 @@ public function process(File $phpcsFile, $stackPtr)
73
77
*/
74
78
private function processIfDirectives (string $ html , File $ phpcsFile ): string
75
79
{
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 )) {
77
81
foreach ($ constructions as $ construction ) {
78
82
// validate {{if <var>}}
79
83
$ this ->validateVariableUsage ($ phpcsFile , $ construction [1 ]);
@@ -93,7 +97,7 @@ private function processIfDirectives(string $html, File $phpcsFile): string
93
97
*/
94
98
private function processDependDirectives (string $ html , File $ phpcsFile ): string
95
99
{
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 )) {
97
101
foreach ($ constructions as $ construction ) {
98
102
// validate {{depend <var>}}
99
103
$ this ->validateVariableUsage ($ phpcsFile , $ construction [1 ]);
@@ -113,7 +117,7 @@ private function processDependDirectives(string $html, File $phpcsFile): string
113
117
*/
114
118
private function processForDirectives (string $ html , File $ phpcsFile ): string
115
119
{
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 )) {
117
121
foreach ($ constructions as $ construction ) {
118
122
// validate {{for in <var>}}
119
123
$ this ->validateVariableUsage ($ phpcsFile , $ construction ['loopData ' ]);
@@ -133,7 +137,7 @@ private function processForDirectives(string $html, File $phpcsFile): string
133
137
*/
134
138
private function processVarDirectivesAndParams (string $ html , File $ phpcsFile ): string
135
139
{
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 )) {
137
141
foreach ($ constructions as $ construction ) {
138
142
if (empty ($ construction [2 ])) {
139
143
continue ;
0 commit comments