From 9d922235a6ec00a1f0a5194162adf8407773f6a9 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Fri, 30 Dec 2022 15:57:52 +0100 Subject: [PATCH] TASK: Update rector to version 0.15.2 (#3237) --- composer.json | 2 +- .../SameClassMethodCallAnalyzer.php | 42 +++++++++++++++++++ .../v0/RemoveAddQueryStringMethodRector.php | 2 +- ...odeMethodsFromTypo3QuerySettingsRector.php | 2 +- ...ommandControllerToSymfonyCommandRector.php | 19 ++++++++- .../FunctionLikeDocParamTypeInferer.php | 24 ++++++++++- 6 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 src/NodeAnalyzer/SameClassMethodCallAnalyzer.php diff --git a/composer.json b/composer.json index 77da157a8..55d624d03 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "nette/utils": "^3.0", "nikic/php-parser": "^4.14", "phpstan/phpstan": "^1.7.12", - "rector/rector": "0.15.1", + "rector/rector": "0.15.2", "symfony/console": "^4.0 || ^5.0 || ^6.0", "symfony/polyfill-php80": "^1.26", "symfony/polyfill-php81": "^1.26", diff --git a/src/NodeAnalyzer/SameClassMethodCallAnalyzer.php b/src/NodeAnalyzer/SameClassMethodCallAnalyzer.php new file mode 100644 index 000000000..ca4d96f27 --- /dev/null +++ b/src/NodeAnalyzer/SameClassMethodCallAnalyzer.php @@ -0,0 +1,42 @@ +reflectionResolver = $reflectionResolver; + } + + /** + * @param MethodCall[] $chainMethodCalls + */ + public function haveSingleClass(array $chainMethodCalls): bool + { + // are method calls located in the same class? + $classOfClassMethod = []; + foreach ($chainMethodCalls as $chainMethodCall) { + $methodReflection = $this->reflectionResolver->resolveMethodReflectionFromMethodCall($chainMethodCall); + if ($methodReflection instanceof MethodReflection) { + $declaringClass = $methodReflection->getDeclaringClass(); + $classOfClassMethod[] = $declaringClass->getName(); + } else { + $classOfClassMethod[] = null; + } + } + $uniqueClasses = \array_unique($classOfClassMethod); + return \count($uniqueClasses) < 2; + } +} diff --git a/src/Rector/v11/v0/RemoveAddQueryStringMethodRector.php b/src/Rector/v11/v0/RemoveAddQueryStringMethodRector.php index 4be5b475d..2fd0cc2c4 100644 --- a/src/Rector/v11/v0/RemoveAddQueryStringMethodRector.php +++ b/src/Rector/v11/v0/RemoveAddQueryStringMethodRector.php @@ -9,8 +9,8 @@ use PHPStan\Type\ObjectType; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; -use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer; use Ssch\TYPO3Rector\Helper\FluentChainMethodCallNodeAnalyzer; +use Ssch\TYPO3Rector\NodeAnalyzer\SameClassMethodCallAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/v11/v0/RemoveLanguageModeMethodsFromTypo3QuerySettingsRector.php b/src/Rector/v11/v0/RemoveLanguageModeMethodsFromTypo3QuerySettingsRector.php index 49646f2c6..e6220dd8c 100644 --- a/src/Rector/v11/v0/RemoveLanguageModeMethodsFromTypo3QuerySettingsRector.php +++ b/src/Rector/v11/v0/RemoveLanguageModeMethodsFromTypo3QuerySettingsRector.php @@ -9,8 +9,8 @@ use PHPStan\Type\ObjectType; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; -use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer; use Ssch\TYPO3Rector\Helper\FluentChainMethodCallNodeAnalyzer; +use Ssch\TYPO3Rector\NodeAnalyzer\SameClassMethodCallAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/v9/v5/ExtbaseCommandControllerToSymfonyCommandRector.php b/src/Rector/v9/v5/ExtbaseCommandControllerToSymfonyCommandRector.php index 5b02e12fb..0855e63a3 100644 --- a/src/Rector/v9/v5/ExtbaseCommandControllerToSymfonyCommandRector.php +++ b/src/Rector/v9/v5/ExtbaseCommandControllerToSymfonyCommandRector.php @@ -16,6 +16,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\Type\ObjectType; +use Rector\BetterPhpDocParser\PhpDocNodeFinder\PhpDocNodeByTypeFinder; use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector; use Rector\Core\Contract\PhpParser\NodePrinterInterface; use Rector\Core\PhpParser\Parser\RectorParser; @@ -95,6 +96,15 @@ final class ExtbaseCommandControllerToSymfonyCommandRector extends AbstractRecto */ private Filesystem $filesystem; + /** + * @var PhpDocNodeByTypeFinder + * @readonly + */ + private PhpDocNodeByTypeFinder $phpDocNodeByTypeFinder; + + /** + * @param PhpDocNodeByTypeFinder $phpDocNodeByTypeFinder + */ public function __construct( RectorParser $rectorParser, FilesFinder $filesFinder, @@ -105,7 +115,8 @@ public function __construct( CommandArrayDecorator $commandArrayDecorator, CommandMethodDecorator $commandMethodDecorator, Filesystem $filesystem, - CommandOutputWritelnDecorator $commandOutputWritelnDecorator + CommandOutputWritelnDecorator $commandOutputWritelnDecorator, + PhpDocNodeByTypeFinder $phpDocNodeByTypeFinder ) { $this->rectorParser = $rectorParser; $this->filesFinder = $filesFinder; @@ -117,6 +128,7 @@ public function __construct( $this->commandMethodDecorator = $commandMethodDecorator; $this->filesystem = $filesystem; $this->commandMethodCallDecorator = $commandOutputWritelnDecorator; + $this->phpDocNodeByTypeFinder = $phpDocNodeByTypeFinder; } /** @@ -191,7 +203,10 @@ public function refactor(Node $node): ?Node $paramTags = $commandPhpDocInfo->getParamTagValueNodes(); /** @var PhpDocTextNode[] $descriptionPhpDocNodes */ - $descriptionPhpDocNodes = $commandPhpDocInfo->getByType(PhpDocTextNode::class); + $descriptionPhpDocNodes = $this->phpDocNodeByTypeFinder->findByType( + $commandPhpDocInfo->getPhpDocNode(), + PhpDocTextNode::class + ); $methodParameters = $commandMethod->params; diff --git a/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php b/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php index ba897d130..5584133a4 100644 --- a/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php +++ b/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php @@ -14,6 +14,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\NodeNameResolver\NodeNameResolver; +use Rector\StaticTypeMapper\StaticTypeMapper; final class FunctionLikeDocParamTypeInferer { @@ -32,14 +33,21 @@ final class FunctionLikeDocParamTypeInferer */ private BetterNodeFinder $betterNodeFinder; + /** + * @readonly + */ + private StaticTypeMapper $staticTypeMapper; + public function __construct( NodeNameResolver $nodeNameResolver, PhpDocInfoFactory $phpDocInfoFactory, - BetterNodeFinder $betterNodeFinder + BetterNodeFinder $betterNodeFinder, + StaticTypeMapper $staticTypeMapper ) { $this->nodeNameResolver = $nodeNameResolver; $this->phpDocInfoFactory = $phpDocInfoFactory; $this->betterNodeFinder = $betterNodeFinder; + $this->staticTypeMapper = $staticTypeMapper; } public function inferParam(Param $param): Type @@ -49,7 +57,19 @@ public function inferParam(Param $param): Type return new MixedType(); } $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike); - $paramTypesByName = $phpDocInfo->getParamTypesByName(); + $paramTagValueNodes = $phpDocInfo->getParamTagValueNodes(); + + $paramTypesByName = []; + + foreach ($paramTagValueNodes as $paramTagValueNode) { + $parameterType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType( + $paramTagValueNode, + $phpDocInfo->getNode() + ); + + $paramTypesByName[$paramTagValueNode->parameterName] = $parameterType; + } + if ([] === $paramTypesByName) { return new MixedType(); }