Skip to content

Commit 94c9bce

Browse files
committed
Fix PHPStan errors
1 parent 58f630e commit 94c9bce

File tree

5 files changed

+13
-56
lines changed

5 files changed

+13
-56
lines changed

phpstan-baseline.neon

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ parameters:
7070
path: src/Analyser/NodeScopeResolver.php
7171

7272
-
73-
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
73+
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Expression\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
7474
count: 1
7575
path: src/Analyser/NodeScopeResolver.php
7676

@@ -276,7 +276,7 @@ parameters:
276276
path: src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php
277277

278278
-
279-
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
279+
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Expression\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
280280
count: 1
281281
path: src/Reflection/BetterReflection/SourceLocator/AutoloadSourceLocator.php
282282

@@ -286,17 +286,17 @@ parameters:
286286
path: src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php
287287

288288
-
289-
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\ClassLike\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_ given\\.$#"
289+
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Expression\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\ClassLike\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_ given\\.$#"
290290
count: 1
291291
path: src/Reflection/BetterReflection/SourceLocator/NewOptimizedDirectorySourceLocator.php
292292

293293
-
294-
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\ClassLike\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_ given\\.$#"
294+
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Expression\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\ClassLike\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_ given\\.$#"
295295
count: 1
296296
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
297297

298298
-
299-
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
299+
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Expression\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
300300
count: 2
301301
path: src/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocator.php
302302

@@ -1799,43 +1799,6 @@ parameters:
17991799
count: 1
18001800
path: tests/PHPStan/Rules/Arrays/AppendedArrayKeyTypeRuleTest.php
18011801

1802-
-
1803-
message: """
1804-
#^Instantiation of deprecated class PHPStan\\\\Rules\\\\DeadCode\\\\NoopRule\\:
1805-
Replaced by PHPStan\\\\Rules\\\\DeadCode\\\\BetterNoopRule$#
1806-
"""
1807-
count: 1
1808-
path: tests/PHPStan/Rules/DeadCode/NoopRuleTest.php
1809-
1810-
-
1811-
message: """
1812-
#^Return type of method PHPStan\\\\Rules\\\\DeadCode\\\\NoopRuleTest\\:\\:getRule\\(\\) has typehint with deprecated class PHPStan\\\\Rules\\\\DeadCode\\\\NoopRule\\:
1813-
Replaced by PHPStan\\\\Rules\\\\DeadCode\\\\BetterNoopRule$#
1814-
"""
1815-
count: 1
1816-
path: tests/PHPStan/Rules/DeadCode/NoopRuleTest.php
1817-
1818-
-
1819-
message: """
1820-
#^Instantiation of deprecated class PHPStan\\\\Rules\\\\Functions\\\\ImplodeFunctionRule\\:
1821-
Replaced by PHPStan\\\\Rules\\\\Functions\\\\ImplodeParameterCastableToStringRuleTest$#
1822-
"""
1823-
count: 1
1824-
path: tests/PHPStan/Rules/Functions/ImplodeFunctionRuleTest.php
1825-
1826-
-
1827-
message: """
1828-
#^Return type of method PHPStan\\\\Rules\\\\Functions\\\\ImplodeFunctionRuleTest\\:\\:getRule\\(\\) has typehint with deprecated class PHPStan\\\\Rules\\\\Functions\\\\ImplodeFunctionRule\\:
1829-
Replaced by PHPStan\\\\Rules\\\\Functions\\\\ImplodeParameterCastableToStringRuleTest$#
1830-
"""
1831-
count: 1
1832-
path: tests/PHPStan/Rules/Functions/ImplodeFunctionRuleTest.php
1833-
1834-
-
1835-
message: "#^PHPDoc tag @var assumes the expression with type PHPStan\\\\Type\\\\Generic\\\\TemplateType is always PHPStan\\\\Type\\\\Generic\\\\TemplateMixedType but it's error\\-prone and dangerous\\.$#"
1836-
count: 1
1837-
path: tests/PHPStan/Type/IterableTypeTest.php
1838-
18391802
-
18401803
message: """
18411804
#^Instantiation of deprecated class PHPStan\\\\Rules\\\\Arrays\\\\EmptyArrayItemRule\\:
@@ -1851,3 +1814,8 @@ parameters:
18511814
"""
18521815
count: 1
18531816
path: tests/PHPStan/Rules/Arrays/EmptyArrayItemRuleTest.php
1817+
1818+
-
1819+
message: "#^PHPDoc tag @var assumes the expression with type PHPStan\\\\Type\\\\Generic\\\\TemplateType is always PHPStan\\\\Type\\\\Generic\\\\TemplateMixedType but it's error\\-prone and dangerous\\.$#"
1820+
count: 1
1821+
path: tests/PHPStan/Type/IterableTypeTest.php

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ private function processStmtNode(
16891689
$finallyScope = $finallyScope->mergeWith($throwPoint->getScope());
16901690
}
16911691

1692-
if ($finallyScope !== null && $stmt->finally !== null) {
1692+
if ($finallyScope !== null) {
16931693
$originalFinallyScope = $finallyScope;
16941694
$finallyResult = $this->processStmtNodes($stmt->finally, $stmt->finally->stmts, $finallyScope, $nodeCallback, $context);
16951695
$alwaysTerminating = $alwaysTerminating || $finallyResult->isAlwaysTerminating();
@@ -2973,9 +2973,6 @@ static function (): void {
29732973
$impurePoints = [];
29742974
foreach ($expr->items as $arrayItem) {
29752975
$itemNodes[] = new LiteralArrayItem($scope, $arrayItem);
2976-
if ($arrayItem === null) {
2977-
continue;
2978-
}
29792976
$nodeCallback($arrayItem, $scope);
29802977
if ($arrayItem->key !== null) {
29812978
$keyResult = $this->processExprNode($stmt, $arrayItem->key, $scope, $nodeCallback, $context->enterDeep());

src/Parser/PhpParserDecorator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\ErrorHandler;
77
use PhpParser\Node;
88
use PhpParser\Parser;
9+
use PHPStan\ShouldNotHappenException;
910
use function sprintf;
1011

1112
final class PhpParserDecorator implements Parser
@@ -33,7 +34,7 @@ public function parse(string $code, ?ErrorHandler $errorHandler = null): array
3334

3435
public function getTokens(): array
3536
{
36-
return $this->wrappedParser->getTokens();
37+
throw new ShouldNotHappenException('PhpParserDecorator::getTokens() should not be called');
3738
}
3839

3940
}

src/Type/Constant/OversizedArrayBuilder.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public function build(Array_ $expr, callable $getTypeCallback): Type
3434
$items = $expr->items;
3535
for ($i = 0; $i < count($items); $i++) {
3636
$item = $items[$i];
37-
if ($item === null) {
38-
continue;
39-
}
4037
if (!$item->unpack) {
4138
continue;
4239
}
@@ -64,9 +61,6 @@ public function build(Array_ $expr, callable $getTypeCallback): Type
6461
}
6562
}
6663
foreach ($items as $item) {
67-
if ($item === null) {
68-
continue;
69-
}
7064
if ($item->unpack) {
7165
throw new ShouldNotHappenException();
7266
}

src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
6565
if ($arrayExpr instanceof Array_) {
6666
$types = null;
6767
foreach ($arrayExpr->items as $item) {
68-
if ($item === null) {
69-
continue;
70-
}
7168
if ($item->unpack) {
7269
$types = null;
7370
break;

0 commit comments

Comments
 (0)