Skip to content

Commit a6c8184

Browse files
committed
magento#121 HelperInTemplate Rule porposal amends
1 parent a50eae5 commit a6c8184

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Magento2/Sniffs/Templates/ThisInTemplateSniff.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
*/
1515
class ThisInTemplateSniff implements Sniff
1616
{
17-
/**
18-
* String representation of warning.
19-
*
20-
* @var string
21-
*/
22-
protected $warningMessageFoundHelper = 'Usage of helpers in templates is discouraged.';
23-
2417
/**
2518
* Warning violation code.
2619
*
@@ -33,7 +26,7 @@ class ThisInTemplateSniff implements Sniff
3326
*
3427
* @var string
3528
*/
36-
protected $warningMessageFoundThis = 'Usage of $this in template files is deprecated.';
29+
protected $warningMessageFoundHelper = 'Usage of helpers in templates is discouraged.';
3730

3831
/**
3932
* Warning violation code.
@@ -42,12 +35,22 @@ class ThisInTemplateSniff implements Sniff
4235
*/
4336
protected $warningCodeFoundThis = 'FoundThis';
4437

38+
/**
39+
* String representation of warning.
40+
*
41+
* @var string
42+
*/
43+
protected $warningMessageFoundThis = 'Usage of $this in template files is deprecated.';
44+
4545
/**
4646
* @inheritdoc
4747
*/
4848
public function register()
4949
{
50-
return [T_VARIABLE];
50+
return [
51+
T_VARIABLE,
52+
T_STRING,
53+
];
5154
}
5255

5356
/**
@@ -59,7 +62,7 @@ public function process(File $phpcsFile, $stackPtr)
5962
if ($tokens[$stackPtr]['content'] === '$this') {
6063
$phpcsFile->addWarning($this->warningMessageFoundThis, $stackPtr, $this->warningCodeFoundThis);
6164
}
62-
if ($tokens[$stackPtr]['content'] === 'helper(') {
65+
if ($tokens[$stackPtr]['content'] === 'helper') {
6366
$phpcsFile->addWarning($this->warningMessageFoundHelper, $stackPtr, $this->warningCodeFoundHelper);
6467
}
6568
}

Magento2/Tests/Templates/ThisInTemplateUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getWarningList()
2828
return [
2929
3 => 2,
3030
4 => 1,
31-
5 => 1,
31+
5 => 2,
3232
];
3333
}
3434
}

0 commit comments

Comments
 (0)