File tree Expand file tree Collapse file tree 5 files changed +103
-0
lines changed Expand file tree Collapse file tree 5 files changed +103
-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 ERROR_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 ->addError (
43+ $ errorMessage ,
44+ $ stackPtr ,
45+ self ::ERROR_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 >
4+
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+
7+ namespace Magento2 \Tests \Legacy ;
8+
9+ use PHP_CodeSniffer \Tests \Standards \AbstractSniffUnitTest ;
10+
11+ class EmailTemplateUnitTest extends AbstractSniffUnitTest
12+ {
13+ /**
14+ * @inheritdoc
15+ */
16+ public function getErrorList ($ testFile = '' )
17+ {
18+ if ($ testFile === 'EmailTemplateUnitTest.1.html ' ) {
19+ return [];
20+ }
21+ if ($ testFile === 'EmailTemplateUnitTest.2.html ' ) {
22+ return [
23+ 1 => 1 ,
24+ 2 => 1 ,
25+ 3 => 2 ,
26+ ];
27+ }
28+
29+ return [];
30+ }
31+
32+ /**
33+ * @inheritdoc
34+ */
35+ public function getWarningList ($ testFile = '' )
36+ {
37+ return [];
38+ }
39+ }
Original file line number Diff line number Diff line change 109109 <severity >10</severity >
110110 <type >error</type >
111111 </rule >
112+ <rule ref =" Magento2.Legacy.EmailTemplate.FoundObsoleteEmailDirective" >
113+ <include-pattern >view/email/*.html</include-pattern >
114+ <include-pattern >view/*/email/*.html</include-pattern >
115+ <severity >10</severity >
116+ <type >error</type >
117+ </rule >
112118
113119 <!-- Severity 9 warnings: Possible security and issues that may cause bugs. -->
114120 <rule ref =" Generic.Files.ByteOrderMark" >
You can’t perform that action at this time.
0 commit comments