33 * Copyright © Magento. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento2 \Sniffs \Templates ;
78
89use PHP_CodeSniffer \Sniffs \Sniff ;
@@ -18,14 +19,28 @@ class ThisInTemplateSniff implements Sniff
1819 *
1920 * @var string
2021 */
21- protected $ warningMessage = 'Usage of $this in template files is deprecated. ' ;
22+ protected $ warningMessageFoundHelper = 'Usage of helpers in templates is discouraged. ' ;
23+
24+ /**
25+ * Warning violation code.
26+ *
27+ * @var string
28+ */
29+ protected $ warningCodeFoundHelper = 'FoundHelper ' ;
30+
31+ /**
32+ * String representation of warning.
33+ *
34+ * @var string
35+ */
36+ protected $ warningMessageFoundThis = 'Usage of $this in template files is deprecated. ' ;
2237
2338 /**
2439 * Warning violation code.
2540 *
2641 * @var string
2742 */
28- protected $ warningCode = 'FoundThis ' ;
43+ protected $ warningCodeFoundThis = 'FoundThis ' ;
2944
3045 /**
3146 * @inheritdoc
@@ -42,7 +57,10 @@ public function process(File $phpcsFile, $stackPtr)
4257 {
4358 $ tokens = $ phpcsFile ->getTokens ();
4459 if ($ tokens [$ stackPtr ]['content ' ] === '$this ' ) {
45- $ phpcsFile ->addWarning ($ this ->warningMessage , $ stackPtr , $ this ->warningCode );
60+ $ phpcsFile ->addWarning ($ this ->warningMessageFoundThis , $ stackPtr , $ this ->warningCodeFoundThis );
61+ }
62+ if ($ tokens [$ stackPtr ]['content ' ] === 'helper( ' ) {
63+ $ phpcsFile ->addWarning ($ this ->warningMessageFoundHelper , $ stackPtr , $ this ->warningCodeFoundHelper );
4664 }
4765 }
4866}
0 commit comments