@@ -16,19 +16,19 @@ class PhtmlTemplateSniff implements Sniff
1616 private const WARNING_CODE_THIS_USAGE = 'ThisUsageObsolete ' ;
1717 private const WARNING_CODE_PROTECTED_PRIVATE_BLOCK_ACCESS = 'ProtectedPrivateBlockAccess ' ;
1818
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+ ] ,
3232 ];
3333
3434 /**
@@ -143,12 +143,12 @@ private function checkHtmlSpecificFiles(File $phpcsFile, int $stackPtr): void
143143 {
144144 $ content = $ phpcsFile ->getTokensAsString ($ stackPtr , 1 );
145145
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 )) {
148148 $ phpcsFile ->addWarning (
149- $ errorMessage ,
149+ $ data [ ' message ' ] ,
150150 $ stackPtr ,
151- self :: WARNING_CODES_OBSOLETE_REGEX_IN_SPECIFIC_PHTML_TEMPLATES [ $ obsoleteRegex ]
151+ $ code
152152 );
153153 }
154154 }
0 commit comments