@@ -16,19 +16,19 @@ class PhtmlTemplateSniff implements Sniff
16
16
private const WARNING_CODE_THIS_USAGE = 'ThisUsageObsolete ' ;
17
17
private const WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS = 'ProtectedPrivateBlockAccess ' ;
18
18
19
- private const WARNING_CODES_OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES = [
20
- '/([" \' ])jquery\/ui\1/ ' => ' FoundJQueryUI ' ,
21
- ' /data-mage-init=(?: \' |")(?!\s*{\s*"[^"]+")/ ' => ' FoundDataMageInit ' ,
22
- ' @x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i ' => ' FoundXMagentoInit ' ,
23
- ];
24
-
25
- private const OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES = [
26
- ' /([" \' ])jquery\/ui\1/ ' => 'Please do not use "jquery/ui" library in templates. Use needed jquery ' .
27
- ' ui widget instead. ' ,
28
- '/data-mage-init=(?: \' |")(?!\s*{\s*"[^"]+")/ ' => ' Please do not initialize JS component in php. Do ' .
29
- 'it in template. ' ,
30
- ' @x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i ' => 'Please do not initialize JS component ' .
31
- ' in php. Do it in template. ' ,
19
+ private const OBSOLETE_REGEX = [
20
+ 'FoundJQueryUI ' => [
21
+ ' pattern ' => ' /([" \' ])jquery\/ui\1/ ' ,
22
+ ' message ' => ' Please do not use "jquery/ui" library in templates. Use needed jquery ui widget instead '
23
+ ],
24
+ ' FoundDataMageInit ' => [
25
+ ' pattern ' => ' /data-mage-init=(?: \' |")(?!\s*{\s*"[^"]+")/ ' ,
26
+ ' message ' => 'Please do not initialize JS component in php. Do it in template '
27
+ ] ,
28
+ 'FoundXMagentoInit ' => [
29
+ 'pattern ' => ' @x-magento-init.>(?!\s*+{\s*"[^"]+"\s*:\s*{\s*"[\w/-]+")@i ' ,
30
+ ' message ' => 'Please do not initialize JS component in php. Do it in template '
31
+ ] ,
32
32
];
33
33
34
34
/**
@@ -143,12 +143,12 @@ private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void
143
143
{
144
144
$ content = $ phpcsFile ->getTokensAsString ($ stackPtr , 1 );
145
145
146
- foreach (self ::OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES as $ obsoleteRegex => $ errorMessage ) {
147
- if (preg_match ($ obsoleteRegex , $ content )) {
146
+ foreach (self ::OBSOLETE_REGEX as $ code => $ data ) {
147
+ if (preg_match ($ data [ ' pattern ' ] , $ content )) {
148
148
$ phpcsFile ->addWarning (
149
- $ errorMessage ,
149
+ $ data [ ' message ' ] ,
150
150
$ stackPtr ,
151
- self :: WARNING_CODES_OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES [ $ obsoleteRegex ]
151
+ $ code
152
152
);
153
153
}
154
154
}
0 commit comments