File tree Expand file tree Collapse file tree 5 files changed +102
-0
lines changed Expand file tree Collapse file tree 5 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento, Inc. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+
7+ namespace Magento2 \Sniffs \Legacy ;
8+
9+ use PHP_CodeSniffer \Files \File ;
10+ use PHP_CodeSniffer \Sniffs \Sniff ;
11+
12+ /**
13+ * Test for obsolete email directives in view/email/*.html
14+ */
15+ class EmailTemplateSniff implements Sniff
16+ {
17+ private const OBSOLETE_EMAIL_DIRECTIVES = [
18+ '/\{\{htmlescape.*?\}\}/i ' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead. ' ,
19+ '/\{\{escapehtml.*?\}\}/i ' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead. ' ,
20+ ];
21+
22+ private const WARNING_CODE = 'FoundObsoleteEmailDirective ' ;
23+
24+ /**
25+ * @inheritdoc
26+ */
27+ public function register (): array
28+ {
29+ return [
30+ T_INLINE_HTML
31+ ];
32+ }
33+
34+ /**
35+ * @inheritDoc
36+ */
37+ public function process (File $ phpcsFile , $ stackPtr )
38+ {
39+ $ content = $ phpcsFile ->getTokens ()[$ stackPtr ]['content ' ];
40+ foreach (self ::OBSOLETE_EMAIL_DIRECTIVES as $ directiveRegex => $ errorMessage ) {
41+ if (preg_match ($ directiveRegex , $ content )) {
42+ $ phpcsFile ->addWarning (
43+ $ errorMessage ,
44+ $ stackPtr ,
45+ self ::WARNING_CODE
46+ );
47+ }
48+ }
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ < h1 > {{var "H1"}}</ h1 >
2+ < h2 > {{var "H2"}}</ h2 >
3+ < p > {{var "p"}} {{var "p"}}</ p >
Original file line number Diff line number Diff line change 1+ < h1 > {{htmlescape "H1"}}</ h1 >
2+ < h2 > {{escapehtml "H2"}}</ h2 >
3+ < p > {{escapehtml "p"}} {{htmlescape "p"}}</ p >
4+ < p class ="greeting "> {{trans "Translateme"}}</ p >
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Copyright © Magento. All rights reserved.
4+ * See COPYING.txt for license details.
5+ */
6+ namespace Magento2 \Tests \Legacy ;
7+
8+ use PHP_CodeSniffer \Tests \Standards \AbstractSniffUnitTest ;
9+
10+ class EmailTemplateUnitTest extends AbstractSniffUnitTest
11+ {
12+ /**
13+ * @inheritdoc
14+ */
15+ public function getErrorList ()
16+ {
17+ return [];
18+ }
19+
20+ /**
21+ * @inheritdoc
22+ */
23+ public function getWarningList ($ testFile = '' )
24+ {
25+ if ($ testFile === 'EmailTemplateUnitTest.1.html ' ) {
26+ return [];
27+ }
28+ if ($ testFile === 'EmailTemplateUnitTest.2.html ' ) {
29+ return [
30+ 1 => 1 ,
31+ 2 => 1 ,
32+ 3 => 2 ,
33+ ];
34+ }
35+
36+ return [];
37+ }
38+ }
Original file line number Diff line number Diff line change 242242 <type >warning</type >
243243 </rule >
244244
245+ <rule ref =" Magento2.Legacy.EmailTemplate.FoundObsoleteEmailDirective" >
246+ <include-pattern >view/email/*.html</include-pattern >
247+ <include-pattern >view/*/email/*.html</include-pattern >
248+ <severity >8</severity >
249+ <type >warning</type >
250+ </rule >
251+
245252 <!-- Severity 7 warnings: General code issues. -->
246253 <rule ref =" Generic.Arrays.DisallowLongArraySyntax" >
247254 <severity >7</severity >
You can’t perform that action at this time.
0 commit comments