mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
fix symfony42 config
This commit is contained in:
parent
68ea5d8b76
commit
4c67d7d6f9
@ -16,16 +16,16 @@
|
||||
"symfony/dependency-injection": "^3.4|^4.2",
|
||||
"symfony/finder": "^3.4|^4.2",
|
||||
"symfony/process": "^3.4|^4.2",
|
||||
"symplify/better-phpdoc-parser": "^5.4.2",
|
||||
"symplify/package-builder": "^5.4.2"
|
||||
"symplify/better-phpdoc-parser": "^5.4.3",
|
||||
"symplify/package-builder": "^5.4.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"ocramius/package-versions": "^1.3",
|
||||
"phpunit/phpunit": "^7.5|^8.0",
|
||||
"symplify/easy-coding-standard": "^5.4.2",
|
||||
"symplify/easy-coding-standard": "^5.4.3",
|
||||
"friendsofphp/php-cs-fixer": "^2.14",
|
||||
"symplify/monorepo-builder": "^5.4.2",
|
||||
"symplify/phpstan-extensions": "^5.4.2",
|
||||
"symplify/monorepo-builder": "^5.4.3",
|
||||
"symplify/phpstan-extensions": "^5.4.3",
|
||||
"thecodingmachine/phpstan-strict-rules": "^0.11.0",
|
||||
"tracy/tracy": "^2.5"
|
||||
},
|
||||
|
@ -67,7 +67,7 @@ services:
|
||||
Symfony\Component\Form\AbstractTypeExtension:
|
||||
getExtendedType: 'getExtendedTypes'
|
||||
|
||||
Rector\Php\Rector\FunctionLike\ReturnTypeDeclarationRector:
|
||||
Rector\Rector\ClassMethod\AddReturnTypeDeclarationRector:
|
||||
Symfony\Component\Form\AbstractTypeExtension:
|
||||
getExtendedTypes: 'iterable'
|
||||
|
||||
|
@ -7,8 +7,11 @@ use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use Rector\NodeTypeResolver\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockAnalyzer;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\ConfiguredCodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
@ -20,12 +23,18 @@ final class ClassReplacerRector extends AbstractRector
|
||||
*/
|
||||
private $oldToNewClasses = [];
|
||||
|
||||
/**
|
||||
* @var DocBlockAnalyzer
|
||||
*/
|
||||
private $docBlockAnalyzer;
|
||||
|
||||
/**
|
||||
* @param string[] $oldToNewClasses
|
||||
*/
|
||||
public function __construct(array $oldToNewClasses)
|
||||
public function __construct(array $oldToNewClasses, DocBlockAnalyzer $docBlockAnalyzer)
|
||||
{
|
||||
$this->oldToNewClasses = $oldToNewClasses;
|
||||
$this->docBlockAnalyzer = $docBlockAnalyzer;
|
||||
}
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
@ -66,29 +75,37 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Name::class];
|
||||
return [Name::class, ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Name $node
|
||||
* @param Name|ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$name = $this->getName($node);
|
||||
if (! $name) {
|
||||
return null;
|
||||
if ($node instanceof Name) {
|
||||
$name = $this->getName($node);
|
||||
if (! $name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$newName = $this->oldToNewClasses[$name] ?? null;
|
||||
if (! $newName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isClassToInterfaceValidChange($node, $newName) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FullyQualified($newName);
|
||||
}
|
||||
|
||||
$newName = $this->oldToNewClasses[$name] ?? null;
|
||||
if (! $newName) {
|
||||
return null;
|
||||
foreach ($this->oldToNewClasses as $oldType => $newType) {
|
||||
$this->docBlockAnalyzer->changeType($node, $oldType, $newType);
|
||||
}
|
||||
|
||||
if ($this->isClassToInterfaceValidChange($node, $newName) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new FullyQualified($newName);
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +142,7 @@ CODE_SAMPLE
|
||||
|
||||
private function isValidUseImportChange(string $newName, UseUse $useUseNode): bool
|
||||
{
|
||||
/** @var Node\Stmt\Use_[]|null $useNodes */
|
||||
/** @var Use_[]|null $useNodes */
|
||||
$useNodes = $useUseNode->getAttribute(Attribute::USE_NODES);
|
||||
if ($useNodes === null) {
|
||||
return true;
|
||||
|
@ -32,7 +32,7 @@ use Rector\Tests\Rector\Class_\ClassReplacerRector\Source\AbstractManualExtensio
|
||||
final class ShortUrlExtension extends AbstractManualExtension
|
||||
{
|
||||
/**
|
||||
* @return Manual_Twig_Filter[]
|
||||
* @return \Manual\Twig\TwigFilter[]
|
||||
*/
|
||||
public function getFilters(): array
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user