Skip to content

Commit 42289c4

Browse files
authored
Merge pull request #365 from PHPCSStandards/feature/universal-constants-modifierkeywordorder-use-utils-constants-getproperties
Universal/ModifierKeywordOrder: use new PHPCSUtils 1.1.0 Constants::getProperties() method
2 parents a8312fb + d6455d1 commit 42289c4

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

Universal/Sniffs/Constants/ModifierKeywordOrderSniff.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
use PHP_CodeSniffer\Files\File;
1414
use PHP_CodeSniffer\Sniffs\Sniff;
15-
use PHP_CodeSniffer\Util\Tokens;
16-
use PHPCSUtils\Tokens\Collections;
15+
use PHPCSUtils\Utils\Constants;
1716
use PHPCSUtils\Utils\Scopes;
1817

1918
/**
@@ -95,36 +94,19 @@ public function process(File $phpcsFile, $stackPtr)
9594
return;
9695
}
9796

98-
$tokens = $phpcsFile->getTokens();
99-
$valid = Collections::constantModifierKeywords() + Tokens::$emptyTokens;
100-
101-
$finalPtr = false;
102-
$visibilityPtr = false;
103-
104-
for ($i = ($stackPtr - 1); $i > 0; $i--) {
105-
if (isset($valid[$tokens[$i]['code']]) === false) {
106-
break;
107-
}
97+
$constantInfo = Constants::getProperties($phpcsFile, $stackPtr);
10898

109-
if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
110-
continue;
111-
}
112-
113-
if ($tokens[$i]['code'] === \T_FINAL) {
114-
$finalPtr = $i;
115-
} else {
116-
$visibilityPtr = $i;
117-
}
118-
}
119-
120-
if ($finalPtr === false || $visibilityPtr === false) {
99+
if ($constantInfo['final_token'] === false || $constantInfo['scope_token'] === false) {
121100
/*
122101
* Either no modifier keywords found at all; or only one type of modifier
123102
* keyword (final or visibility) declared, but not both. No ordering needed.
124103
*/
125104
return;
126105
}
127106

107+
$finalPtr = $constantInfo['final_token'];
108+
$visibilityPtr = $constantInfo['scope_token'];
109+
128110
if ($visibilityPtr < $finalPtr) {
129111
$phpcsFile->recordMetric($stackPtr, self::METRIC_NAME, self::VISIBILITY_FINAL);
130112
} else {

0 commit comments

Comments
 (0)