Skip to content

Commit 750260e

Browse files
committed
AC-601: Create phpcs static check for AbstractBlockTest
1 parent 515563c commit 750260e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Magento2/Sniffs/Legacy/AbstractBlockSniff.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class AbstractBlockSniff implements Sniff
1212
{
13-
const CHILD_HTML_METHOD = 'getChildHtml';
14-
const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml';
13+
private const CHILD_HTML_METHOD = 'getChildHtml';
14+
private const CHILD_CHILD_HTML_METHOD = 'getChildChildHtml';
1515

1616
/**
1717
* Warning violation code.
@@ -38,18 +38,13 @@ public function process(File $phpcsFile, $stackPtr)
3838
if (!isset($phpcsFile->getTokens()[$stackPtr + 1]['content'])) {
3939
return;
4040
}
41+
4142
$content = $phpcsFile->getTokens()[$stackPtr + 1]['content'];
42-
$isTheNextMethodGetChildSomething = in_array(
43-
$content,
44-
[
45-
self::CHILD_HTML_METHOD,
46-
self::CHILD_CHILD_HTML_METHOD
47-
]
48-
);
49-
if (!$isTheNextMethodGetChildSomething) {
43+
44+
if (!$this->isApplicable($content)) {
5045
return;
5146
}
52-
47+
5348
$paramsCount = $this->getParametersCount($phpcsFile, $stackPtr + 1);
5449
if ($content === self::CHILD_HTML_METHOD && $paramsCount >= 3) {
5550
$phpcsFile->addError(
@@ -67,6 +62,17 @@ public function process(File $phpcsFile, $stackPtr)
6762
}
6863
}
6964

65+
/**
66+
* Return if it is applicable to do the check
67+
*
68+
* @param String $content
69+
* @return bool
70+
*/
71+
private function isApplicable(String $content): bool
72+
{
73+
return in_array($content, [self::CHILD_HTML_METHOD, self::CHILD_CHILD_HTML_METHOD]);
74+
}
75+
7076
/**
7177
* Get the quantity of parameters on a method
7278
*

0 commit comments

Comments
 (0)