Skip to content

Commit 628336c

Browse files
committed
Fix static analysis
- Remove PHPStan workarounds and require fixed PHPCS version - PHAN doesn't hard depend on AST anymore in recent versions
1 parent 71cceb7 commit 628336c

File tree

5 files changed

+10
-17
lines changed

5 files changed

+10
-17
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ cache:
2323
before_script:
2424
- if [ "${DEPENDENCIES}" = "lowest" ]; then composer update --prefer-lowest --prefer-dist --no-interaction --no-progress; fi;
2525
- if [ "${DEPENDENCIES}" = "highest" ]; then composer update --prefer-dist --no-interaction --no-progress; fi;
26-
- if [ "${DEPENDENCIES}" = "highest" ]; then pecl install -f ast-1.0.5; fi; # Install AST extension, as phan requires it
27-
- if [ "${DEPENDENCIES}" = "highest" ]; then composer require phan/phan --dev; fi; # Install phan, now that we have the AST extension
26+
- if [ "${DEPENDENCIES}" = "highest" ]; then pecl install -f ast-1.0.5; fi; # Install AST extension, as phan uses it
2827

2928
script:
3029
- xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd MO4/ruleset.xml # validate MO4's ruleset XML

MO4/Sniffs/Commenting/PropertyCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function processTokenWithinScope(
160160
$isCommentOneLiner
161161
= $tokens[$commentStart]['line'] === $tokens[$commentEnd]['line'];
162162

163-
$length = (int) ($commentEnd - $commentStart + 1);
163+
$length = ($commentEnd - $commentStart + 1);
164164
$tokensAsString = $phpcsFile->getTokensAsString(
165165
$commentStart,
166166
$length

MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ private function getUseImport(File $phpcsFile, int $stackPtr)
182182
return false;
183183
}
184184

185-
$start = (int) $start;
186185
$end = (int) $phpcsFile->findNext($importTokens, $start, null, true);
187186
$import = $phpcsFile->getTokensAsString($start, ($end - $start));
188187

@@ -307,21 +306,21 @@ private function findNewDestination(
307306
$line = $prevLine;
308307
}
309308

310-
$prevPtr = $phpcsFile->findPrevious(T_USE, ((int) $ptr - 1));
309+
$prevPtr = $phpcsFile->findPrevious(T_USE, ($ptr - 1));
311310
if ($prevPtr === false) {
312311
break;
313312
}
314313

315314
$prevLine = $tokens[$prevPtr]['line'];
316315
// phpcs:disable
317316
/** @var array<string> $prevImportArr */
318-
$prevImportArr = $this->getUseImport($phpcsFile, (int) $prevPtr);
317+
$prevImportArr = $this->getUseImport($phpcsFile, $prevPtr);
319318
// phpcs:enable
320319
} while ($prevLine === ($line - 1)
321320
&& ($this->compareString($prevImportArr['content'], $import) > 0)
322321
);
323322

324-
return (int) $ptr;
323+
return $ptr;
325324

326325
}//end findNewDestination()
327326

MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public function process(File $phpcsFile, $stackPtr): void
9090
$nsSep = $phpcsFile->findNext($scanTokens, ($stackPtr + 1));
9191

9292
while ($nsSep !== false) {
93-
$nsSep = (int) $nsSep;
94-
9593
$classNameEnd = (int) $phpcsFile->findNext(
9694
$this->classNameTokens,
9795
$nsSep,
@@ -145,8 +143,6 @@ public function process(File $phpcsFile, $stackPtr): void
145143
continue;
146144
}
147145

148-
$docCommentStringPtr = (int) $docCommentStringPtr;
149-
150146
$docLine = $tokens[$docCommentStringPtr]['content'];
151147

152148
$docLineTokens = PregLibrary::mo4_preg_split(
@@ -219,7 +215,7 @@ protected function getUseStatements(
219215
while ($useTokenPtr !== false) {
220216
$classNameStart = (int) $phpcsFile->findNext(
221217
PHP_CodeSniffer_Tokens::$emptyTokens,
222-
((int) $useTokenPtr + 1),
218+
($useTokenPtr + 1),
223219
$end,
224220
true
225221
);
@@ -244,7 +240,7 @@ protected function getUseStatements(
244240

245241
$aliasNamePtr = $phpcsFile->findPrevious(
246242
PHP_CodeSniffer_Tokens::$emptyTokens,
247-
((int) $useEnd - 1),
243+
($useEnd - 1),
248244
null,
249245
true
250246
);
@@ -254,7 +250,7 @@ protected function getUseStatements(
254250

255251
$className = $this->getFullyQualifiedClassName($className);
256252
$useStatements[$className] = $tokens[$aliasNamePtr]['content'];
257-
$i = ((int) $useEnd + 1);
253+
$i = ($useEnd + 1);
258254

259255
if ($tokens[$useEnd]['code'] === T_COMMA) {
260256
$useTokenPtr = $i;
@@ -291,8 +287,6 @@ protected function getNamespace(File $phpcsFile, int $start, int $end): string
291287
return '';
292288
}
293289

294-
$namespaceStart = (int) $namespaceStart;
295-
296290
$namespaceEnd = (int) $phpcsFile->findNext(
297291
$this->classNameTokens,
298292
($namespaceStart + 1),

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"source": "https://github.com/mayflower/mo4-coding-standard"
2323
},
2424
"require-dev": {
25+
"phan/phan": "^2.4.8",
2526
"phpstan/phpdoc-parser": "^0.4.1",
2627
"phpstan/phpstan": "^0.12.2",
2728
"phpstan/phpstan-strict-rules": "^0.12",
@@ -32,6 +33,6 @@
3233
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
3334
"escapestudios/symfony2-coding-standard": "^3.10.0",
3435
"slevomat/coding-standard": "^6.0.2",
35-
"squizlabs/php_codesniffer": "^3.5.3"
36+
"squizlabs/php_codesniffer": "^3.5.4"
3637
}
3738
}

0 commit comments

Comments
 (0)