Skip to content

Commit 53cf44b

Browse files
author
Lars Roettig
committed
#24: [New Rule] Static methods SHOULD NOT be used
1 parent 5fa9179 commit 53cf44b

File tree

2 files changed

+270
-362
lines changed

2 files changed

+270
-362
lines changed

Magento/Sniffs/Functions/StaticFunctionSniff.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class StaticFunctionSniff implements Sniff
1919
*
2020
* @var string
2121
*/
22-
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
2322
protected $warningMessage = 'The use of `static` methods is discouraged';
2423

2524
/**
@@ -45,17 +44,18 @@ public function process(File $phpcsFile, $stackPtr)
4544
$posOfFunction = $phpcsFile->findNext(T_FUNCTION, $stackPtr) + 1;
4645
$tokens = array_slice($phpcsFile->getTokens(), $stackPtr, $posOfFunction - $stackPtr);
4746

48-
$allowedTypes = ['T_STATIC' => '', 'T_WHITESPACE' => '', 'T_FUNCTION' => ''];
47+
$allowedTypes = [T_STATIC => true, T_WHITESPACE => true, T_FUNCTION => true];
4948

5049
foreach ($tokens as $token) {
51-
$type = $token['type'];
52-
if (!array_key_exists($type, $allowedTypes)) {
50+
51+
$code = $token['code'];
52+
if (!array_key_exists($code, $allowedTypes)) {
5353
break;
5454
}
5555

56-
if ($type === 'T_FUNCTION') {
56+
if ($code === T_FUNCTION) {
5757
$phpcsFile->addWarning($this->warningMessage, $posOfFunction, $this->warningCode);
5858
}
5959
}
6060
}
61-
}
61+
}

0 commit comments

Comments
 (0)