Skip to content

Commit

Permalink
Cleanup phpstan errors (#5044)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 19, 2023
1 parent a3d2fcd commit 1fe0f12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 35 deletions.
38 changes: 6 additions & 32 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ parameters:
scanDirectories:
- stubs

scanFiles:
- src/Contract/PhpParser/Node/StmtsAwareInterface.php

checkGenericClassInNonGenericObjectType: false

excludePaths:
Expand Down Expand Up @@ -171,10 +174,6 @@ parameters:
# many internal cases
- '#Calling (.*?) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version#'

-
path: src/Bootstrap/RectorConfigsResolver.php
message: '#Method Rector\\Core\\Bootstrap\\RectorConfigsResolver\:\:resolveFromInput\(\) should return string\|null but returns string\|false#'

# known value object, nullable due to typed property
-
message: '#Cannot call method (.*?)\(\) on (.*?)\\ProcessPool\|null#'
Expand Down Expand Up @@ -229,8 +228,6 @@ parameters:
-
message: '#Use value object over return of values#'
paths:
- src/Application/ApplicationFileProcessor.php
- packages/Parallel/Application/ParallelFileProcessor.php
- packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser/ArrayParser.php
- rules/EarlyReturn/Rector/If_/ChangeNestedIfsToEarlyReturnRector.php
- rules/Php70/EregToPcreTransformer.php
Expand Down Expand Up @@ -419,10 +416,6 @@ parameters:
path: utils/ChangelogGenerator

# std class api
-
message: '#Function "property_exists\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
path: utils/ChangelogGenerator

-
message: '#Parameter \#1 \$phpVersion of method Rector\\Config\\RectorConfig\:\:phpVersion\(\) expects 50200\|50300\|50400\|50500\|50600\|70000\|70100\|70200\|70300\|70400\|80000\|80100\|80200\|100000, (.*?) given#'
path: rules-tests
Expand All @@ -432,11 +425,6 @@ parameters:
paths:
- rules-tests/*/config/*

-
message: '#Offset \d does not exist on array<string, string>#'
paths:
- *Test.php

- '#Parameter \#1 \$expected of method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) expects class\-string<object>, string given#'

- '#Parameter \#3 \$nodeClass of method Rector\\Tests\\BetterPhpDocParser\\PhpDocParser\\TagValueNodeReprint\\TagValueNodeReprintTest\:\:doTestPrintedPhpDocInfo\(\) expects class\-string<PhpParser\\Node>, string given#'
Expand Down Expand Up @@ -477,25 +465,15 @@ parameters:
# false positive on enums
- '#Method Rector\\Core\\Console\\Command\\SetupCICommand\:\:resolveCurrentCI\(\) never returns (.*?) so it can be removed from the return type#'

- '#Access to an undefined property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
- '#Access to an undefined property PhpParser\\Node\\Stmt\\ClassLike\|Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'

-
message: '#Method "renameVariableInFunctionLike\(\)" returns bool type, so the name should start with is/has/was#'
path: rules/Naming/VariableRenamer.php

# resolve continually
- '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts \(array<PhpParser\\Node\\Stmt>\|null\) does not accept array<PhpParser\\Node\\Stmt\|null>#'

# stmts aware/expression generics
- '#PhpParser\\Node\\Stmt\\Expression is not generic#'
- '#Access to an undefined property PhpParser\\Node\\Stmt&Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'

- '#Parameter \#3 \$assign of method Rector\\CodeQuality\\Rector\\FunctionLike\\SimplifyUselessVariableRector\:\:processSimplifyUselessVariable\(\) expects PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Expr\\AssignOp, PhpParser\\Node\\Expr given#'

- '#Access to an undefined property PhpParser\\Node\\Stmt\\ClassLike\|PhpParser\\Node\\Stmt\\Declare_\|Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
- '#Access to an undefined property \(PhpParser\\Node\\Stmt&Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\)\|PhpParser\\Node\\Stmt\\ClassLike\|PhpParser\\Node\\Stmt\\Declare_\:\:\$stmts#'

# looks like a bug in the PHPStan rule, see https://github.com/rectorphp/rector-src/pull/3645#issuecomment-1561294527
-
message: '#Method name "(get|has|set)Attribute\(\)" is used in multiple traits\. Make it unique to avoid conflicts#'
Expand Down Expand Up @@ -563,15 +541,8 @@ parameters:
message: '#Function "(class_exists|interface_exists)\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
path: packages/Skipper/SkipCriteriaResolver/SkippedClassResolver.php

# generic for other packages too
-
message: '#Parameters should use "PhpParser\\Node\\Identifier\|string" types as the only types passed to this method#'
path: packages/NodeNameResolver/NodeNameResolver.php

# remove in next step
- '#Call to deprecated method markAsChanged\(\) of class Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo#'
- '#Method "(importNames|renamePhpDocType)\(\)" returns bool type, so the name should start with is/has/was#'
- '#Call to an undefined method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:markAsChanged\(\)#'

# ignore until PHPParser returns more precise types
-
Expand All @@ -584,3 +555,6 @@ parameters:
message: '#Anonymous function has an unused use \$configuration#'
path: packages/Parallel/Application/ParallelFileProcessor.php

# stmts aware interface
- '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
- '#undefined property (.*?)\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface::\$stmts#'
6 changes: 3 additions & 3 deletions src/Application/Collector/CollectorNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function enterNode(Node $node)
{
$collectors = $this->collectorRegistry->getCollectors($node::class);

foreach ($collectors as $collector) {
/** @var Scope $scope */
$scope = $node->getAttribute(AttributeKey::SCOPE);
/** @var Scope $scope */
$scope = $node->getAttribute(AttributeKey::SCOPE);

foreach ($collectors as $collector) {
try {
$collectedData = $collector->processNode($node, $scope);
} catch (Throwable) {
Expand Down

0 comments on commit 1fe0f12

Please sign in to comment.