Skip to content

Commit

Permalink
TASK: Update rector to version 0.15.2 (#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon authored Dec 30, 2022
1 parent 0b70082 commit 9d92223
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 42 additions & 0 deletions src/NodeAnalyzer/SameClassMethodCallAnalyzer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\NodeAnalyzer;

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Reflection\MethodReflection;
use Rector\Core\Reflection\ReflectionResolver;

final class SameClassMethodCallAnalyzer
{
/**
* @readonly
*/
private ReflectionResolver $reflectionResolver;

public function __construct(ReflectionResolver $reflectionResolver)
{
$this->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;
}
}
2 changes: 1 addition & 1 deletion src/Rector/v11/v0/RemoveAddQueryStringMethodRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +96,15 @@ final class ExtbaseCommandControllerToSymfonyCommandRector extends AbstractRecto
*/
private Filesystem $filesystem;

/**
* @var PhpDocNodeByTypeFinder<PhpDocTextNode>
* @readonly
*/
private PhpDocNodeByTypeFinder $phpDocNodeByTypeFinder;

/**
* @param PhpDocNodeByTypeFinder<PhpDocTextNode> $phpDocNodeByTypeFinder
*/
public function __construct(
RectorParser $rectorParser,
FilesFinder $filesFinder,
Expand All @@ -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;
Expand All @@ -117,6 +128,7 @@ public function __construct(
$this->commandMethodDecorator = $commandMethodDecorator;
$this->filesystem = $filesystem;
$this->commandMethodCallDecorator = $commandOutputWritelnDecorator;
$this->phpDocNodeByTypeFinder = $phpDocNodeByTypeFinder;
}

/**
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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();
}
Expand Down

0 comments on commit 9d92223

Please sign in to comment.