Skip to content

Commit

Permalink
Bump symplify/phpstan-rules deps (#3894)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 19, 2023
1 parent e6d869b commit 5b990ff
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 68 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
"rector/rector-generator": "dev-main",
"spatie/enum": "^3.13",
"symplify/easy-ci": "^11.1.18",
"symplify/easy-coding-standard": "^11.1.18",
"symplify/phpstan-extensions": "^11.1.18",
"symplify/phpstan-rules": "^11.1.28",
"symplify/easy-coding-standard": "^11.3",
"symplify/phpstan-extensions": "^11.2",
"symplify/phpstan-rules": "^12.0",
"symplify/rule-doc-generator": "^11.1.18",
"symplify/vendor-patches": "^11.2.3",
"tomasvotruba/cognitive-complexity": "^0.0.1",
Expand Down
62 changes: 8 additions & 54 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ parameters:
-
message: '#Array (with keys|destruct) is not allowed\. Use value object to pass data instead#'
path: rules/Php70/EregToPcreTransformer.php

-
message: '#Use explicit return value over magic &reference#'
path: rules/Php70/EregToPcreTransformer.php
Expand All @@ -102,10 +103,6 @@ parameters:

- '#Method (.*?) should return array<PhpParser\\Node\\(.*?)\> but returns array<PhpParser\\Node\>#'

- '#Access to an undefined property PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable\:\:\$name#'

- '#PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable given#'

-
message: '#There should be no empty class#'
paths:
Expand Down Expand Up @@ -168,7 +165,6 @@ parameters:
- '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory\:\:uniquateTypes\(\) should return array<TType of PHPStan\\Type\\Type\> but returns array<int, PHPStan\\Type\\Type\>#'

# resolve later
- '#Method "(.*?)\(\)" only calling another method call and has no added value\. Use the inlined call instead#'
- '#Method "processRenameVariable\(\)" returns bool type, so the name should start with is/has/was#'

- '#Method "resolveObjectType\(\)" returns bool type, so the name should start with is/has/was#'
Expand Down Expand Up @@ -373,11 +369,6 @@ parameters:
message: '#Call to static method Webmozart\\Assert\\Assert\:\:allString\(\) with array<class\-string<Rector\\Core\\Contract\\Rector\\RectorInterface>> will always evaluate to true#'
path: packages/Config/RectorConfig.php

# hash key
-
path: rules/Renaming/NodeManipulator/ClassRenamer.php
message: '#Use separate function calls with readable variable names#'

- '#Cognitive complexity for "Rector\\NodeTypeResolver\\PHPStan\\Scope\\PHPStanNodeScopeResolver\:\:processNodes\(\)" is \d+, keep it under 10#'

# depends on falsy docs
Expand Down Expand Up @@ -488,24 +479,6 @@ parameters:
# part of tests
- '#Call to method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with 50200\|50300\|50400\|50500\|50600\|70000\|70100\|70200\|70300\|70400\|80000\|80100\|80200\|100000 will always evaluate to true#'

-
message: '#Method call return value that should be used, but is not#'
paths:
- src/Console/Output/RectorOutputStyle.php
- rules/Compatibility/NodeFactory/ConstructorClassMethodFactory.php
- src/Application/ChangedNodeScopeRefresher.php
- rules/TypeDeclaration/TypeNormalizer.php
- rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNewArrayRector.php
- rules/Removing/NodeManipulator/ComplexNodeRemover.php
- rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php
- packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
- packages/PhpDocParser/PhpDocParser/PhpDocNodeTraverser.php

-
message: '#Method call return value that should be used, but is not#'
path: src/PhpParser/Node/NodeFactory.php
count: 1

# false postive, on trait use in multiple classes
-
message: '#Method name "(.*?)Attribute\(\)" is used in multiple traits\. Make it unique to avoid conflicts#'
Expand Down Expand Up @@ -649,10 +622,6 @@ parameters:
- src/DependencyInjection/DefinitionFinder.php

# changelog generator
-
message: '#Do not use chained method calls\. Put each on separated lines#'
path: utils/ChangelogGenerator/GithubApiCaller.php

-
message: '#Anonymous (variable|variables) in#'
path: utils/ChangelogGenerator
Expand Down Expand Up @@ -699,10 +668,6 @@ parameters:
message: '#Method call return value that should be used, but is not#'
path: packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php

-
message: '#"Tests" namespace cannot be used outside of "tests" directory#'
path: utils-tests

# trusted items
- '#Parameter \#1 \$nodes of method PhpParser\\PrettyPrinterAbstract\:\:pCommaSeparatedMultiline\(\) expects array<PhpParser\\Node>, array<PhpParser\\Node\\Expr\\ArrayItem\|null> given#'

Expand Down Expand Up @@ -766,15 +731,6 @@ parameters:
message: '#Method "renameVariableInFunctionLike\(\)" returns bool type, so the name should start with is/has/was#'
path: rules/Naming/VariableRenamer.php

-
message: '#Method call return value that should be used, but is not#'
paths:
- rules/Naming/ParamRenamer/ParamRenamer.php
- rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php
- rules/Naming/Rector/Assign/RenameVariableToMatchMethodCallReturnTypeRector.php
- rules/Naming/Rector/ClassMethod/RenameVariableToMatchNewTypeRector.php
- rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php

# next to resolve
- '#Cognitive complexity for "Rector\\EarlyReturn\\Rector\\Return_\\PreparedValueToEarlyReturnRector\:\:refactor\(\)" is 11, keep it under 10#'
- '#Cognitive complexity for "Rector\\CodeQuality\\Rector\\Foreach_\\SimplifyForeachToCoalescingRector\:\:refactor\(\)" is 16, keep it under 10#'
Expand All @@ -786,10 +742,6 @@ parameters:
- '#(Matching|Fetching) deprecated class constant (NEXT_NODE|PREVIOUS_NODE) of class Rector\\NodeTypeResolver\\Node\\AttributeKey#'
- '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts \(array<PhpParser\\Node\\Stmt>\|null\) does not accept array<PhpParser\\Node\\Stmt\|null>#'

# make autoload of php-parser in rector first
- '#but class PhpParser\\Node\\Stmt\\Expression is not generic#'
- '#Parameter \#3 \$assign of method Rector\\CodeQuality\\Rector\\FunctionLike\\SimplifyUselessVariableRector\:\:processSimplifyUselessVariable\(\) expects PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Expr\\AssignOp, PhpParser\\Node\\Expr given#'

# deprecated
- '#Register "Rector\\Php80\\Rector\\FunctionLike\\UnionTypesRector" service to "php80\.php" config set#'
- '#Fetching class constant class of deprecated class Rector\\CodeQuality\\Rector\\ClassMethod\\NarrowUnionTypeDocRector#'
Expand All @@ -800,12 +752,14 @@ parameters:
message: '#Do not use static property#'
path: src/Kernel/RectorKernel.php

# this is due to compare VersionResolver::PACKAGE_VERSION to verify on rector-src
-
message: '#Public method "Rector\\Core\\Kernel\\RectorKernel\:\:clearCache\(\)" is never used#'
path: src/Kernel/RectorKernel.php

# '@package_version@' compare with '@package_version@' to verify on rector-src
-
message: '#Strict comparison using \!\=\= between .* and .* will always evaluate to false#'
path: src/Kernel/RectorKernel.php

# expression generics
- '#PHPDoc tag @return contains generic type PhpParser\\Node\\Stmt\\Expression<PhpParser\\Node\\Expr\\Assign> but class PhpParser\\Node\\Stmt\\Expression is not generic#'
- '#PHPDoc tag @var for variable \$previousStmt contains generic type PhpParser\\Node\\Stmt\\Expression<PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Expr\\AssignOp> but class PhpParser\\Node\\Stmt\\Expression is not generic#'
- '#Parameter \#3 \$assign of method Rector\\CodeQuality\\Rector\\FunctionLike\\SimplifyUselessVariableRector\:\:processSimplifyUselessVariable\(\) expects PhpParser\\Node\\Expr\\Assign\|PhpParser\\Node\\Expr\\AssignOp, PhpParser\\Node\\Expr given#'
- '#Anonymous variable in a `\$stmtsAware\->stmts\[\$key \- 1\]\->\.\.\.\(\)` method call can lead to false dead methods\. Make sure the variable type is known#'
- '#Anonymous variable in a `\$parentNode\->stmts\[\$key\]\->\.\.\.\(\)` method call can lead to false dead methods\. Make sure the variable type is known#'
5 changes: 5 additions & 0 deletions rules/Naming/Guard/BreakingVariableRenameGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Error;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -113,6 +114,10 @@ public function shouldSkipParam(
return true;
}

if ($param->var instanceof Error) {
return true;
}

if ($this->isVariableAlreadyDefined($param->var, $currentName)) {
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Rector\Naming\PropertyRenamer;

use PhpParser\Node\Expr\Error;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
Expand Down Expand Up @@ -85,6 +87,10 @@ private function renameParamVarNameAndVariableUsage(
string $desiredPropertyName,
Param $param
): void {
if ($param->var instanceof Error) {
return;
}

$classMethodPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);

$currentParamName = $this->nodeNameResolver->getName($param);
Expand All @@ -98,7 +104,7 @@ private function renameParamVarNameAndVariableUsage(
/** @var string $paramVarName */
$paramVarName = $param->var->name;
$this->renameParamDoc($classMethodPhpDocInfo, $param, $paramVarName, $desiredPropertyName);
$param->var->name = $desiredPropertyName;
$param->var = new Variable($desiredPropertyName);

$this->variableRenamer->renameVariableInFunctionLike($classMethod, $paramVarName, $desiredPropertyName);
}
Expand Down
5 changes: 5 additions & 0 deletions rules/Naming/ValueObjectFactory/ParamRenameFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Error;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -25,6 +26,10 @@ public function __construct(

public function createFromResolvedExpectedName(Param $param, string $expectedName): ?ParamRename
{
if ($param->var instanceof Error) {
return null;
}

/** @var ClassMethod|Function_|Closure|ArrowFunction|null $functionLike */
$functionLike = $this->betterNodeFinder->findParentType($param, FunctionLike::class);
if ($functionLike === null) {
Expand Down
4 changes: 4 additions & 0 deletions rules/Php72/NodeManipulator/ClosureNestedUsesDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function applyNestedUses(Closure $anonymousFunctionNode, Variable $useVar
private function collectUsesEqual(Closure $closure, array $uses, Variable $useVariable): array
{
foreach ($closure->params as $param) {
if (! $param->var instanceof Variable) {
continue;
}

if ($this->nodeComparator->areNodesEqual($param->var, $useVariable)) {
$uses[] = new ClosureUse($param->var);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
Expand Down Expand Up @@ -166,7 +167,8 @@ public function refactor(Node $node): ?Node
}

// property name has higher priority
$param->var->name = $this->getName($property);
$paramName = $this->getName($property);
$param->var = new Variable($paramName);

$param->flags = $property->flags;
// Copy over attributes of the "old" property
Expand Down
5 changes: 4 additions & 1 deletion src/Exception/Cache/StaleContainerCacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
namespace Rector\Core\Exception\Cache;

use RuntimeException;
final class StaleContainerCacheException extends RuntimeException {}

final class StaleContainerCacheException extends RuntimeException
{
}
11 changes: 6 additions & 5 deletions src/Kernel/CacheInvalidatingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace Rector\Core\Kernel;

use Throwable;
use UnitEnum;
use Rector\Core\Exception\Cache\StaleContainerCacheException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Throwable;
use UnitEnum;

final class CacheInvalidatingContainer implements ContainerInterface {
final class CacheInvalidatingContainer implements ContainerInterface
{
public function __construct(
private readonly ContainerInterface $container
)
{}
) {
}

public function set(string $id, ?object $service): void
{
Expand Down
5 changes: 5 additions & 0 deletions src/NodeAnalyzer/ParamAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\Error;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -42,6 +43,10 @@ public function isParamUsedInClassMethod(ClassMethod $classMethod, Param $param)
{
$isParamUsed = false;

if ($param->var instanceof Error) {
return false;
}

$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod->stmts, function (Node $node) use (
&$isParamUsed,
$param
Expand Down
2 changes: 1 addition & 1 deletion src/NodeManipulator/AssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function isLeftPartOfAssign(Node $node): bool
*
* Compare same node to ensure php_doc_info info not be checked
*/
return $this->nodeComparator->areSameNode($parentNode->var, $node);
return $this->nodeComparator->areSameNode($parentNode->var, $node);
}

if ($this->isOnArrayDestructuring($parentNode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -191,8 +192,8 @@ private function incrementParamIfExists(
}

if ($name !== $newName) {
$param->var = clone $param->var;
$param->var->name = $name;
// $param->var = clone $param->var;
$param->var = new Variable($name);
}
}

Expand Down

0 comments on commit 5b990ff

Please sign in to comment.