fix symfony42 config

This commit is contained in:
Tomas Votruba 2019-02-10 22:15:51 +01:00
parent 68ea5d8b76
commit 4c67d7d6f9
4 changed files with 39 additions and 22 deletions

View File

@ -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"
},

View File

@ -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'

View File

@ -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;

View File

@ -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
{