Merge pull request #33 from TomasVotruba/nette-configurator

[Nette] Configurator class name change
This commit is contained in:
Tomáš Votruba 2017-09-07 00:31:24 +02:00 committed by GitHub
commit c5ae138efd
27 changed files with 243 additions and 131 deletions

View File

@ -10,15 +10,15 @@
"php": "^7.1",
"symfony/console": "^3.3",
"symfony/dependency-injection": "^3.3",
"nikic/php-parser": "4.0.x-dev as 3.0.2",
"nikic/php-parser": "4.0.x-dev as 3.1",
"nette/utils": "^2.4"
},
"require-dev": {
"phpstan/phpstan": "^0.8",
"phpunit/phpunit": "^6.2",
"slam/php-cs-fixer-extensions": "^1.4",
"slam/php-cs-fixer-extensions": "^1.5",
"symfony/form": "^3.3",
"symplify/easy-coding-standard": "^2.2",
"symplify/easy-coding-standard": "^2.3",
"tracy/tracy": "^2.4"
},
"autoload": {

View File

@ -20,7 +20,7 @@ Anonymous classes are skipped.
You can get `class`
```php
$class = (string) $node->getAttribute('class');
$class = (string) $node->getAttribute(Attribute::CLASS_NAME);
if (Strings::endsWith($class, 'Command')) {
// we are in Command class
@ -29,9 +29,9 @@ if (Strings::endsWith($class, 'Command')) {
// to be sure it's console command
/** @var PhpParser\Node\Name\FullyQualified $fqnName */
$classNode = $node->getAttribute('class_node');
$classNode = $node->getAttribute(Attribute::CLASS_NODE);
$fqnName = $classNode->extends->getAttribute('resolvedName');
$fqnName = $classNode->extends->getAttribute(Attribute::RESOLVED_NAME);
if ($fqnName->toString() === 'Symfony\Component\Console\Command') {
// we are sure it's child of Symfony\Console Command class
@ -42,7 +42,7 @@ or `type` attribute:
```php
/** @var string $type */
$type = $node->var->getAttribute('type');
$type = $node->var->getAttribute(Attribute::TYPE);
if ($type === 'Nette\Application\UI\Form') {
// this is Nette\Application\UI\Form variable

View File

@ -12,6 +12,7 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use PhpParser\NodeVisitorAbstract;
use Rector\Node\Attribute;
use Rector\NodeTypeResolver\TypeContext;
/**
@ -85,7 +86,7 @@ final class TypeResolver extends NodeVisitorAbstract
private function getTypeFromNewNode(New_ $newNode): string
{
/** @var FullyQualified $fqnName */
$fqnName = $newNode->class->getAttribute('resolvedName');
$fqnName = $newNode->class->getAttribute(Attribute::RESOLVED_NAME);
return $fqnName->toString();
}
@ -94,7 +95,7 @@ final class TypeResolver extends NodeVisitorAbstract
{
$variableType = null;
$parentNode = $variableNode->getAttribute('parent');
$parentNode = $variableNode->getAttribute(Attribute::PARENT_NODE);
if ($parentNode instanceof Assign) {
if ($parentNode->expr instanceof New_) {
$variableName = $variableNode->name;

View File

@ -6,6 +6,7 @@ use Nette\Utils\Html;
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use Rector\Contract\Parser\ParserInterface;
use Rector\Node\Attribute;
use Rector\NodeTraverser\StandaloneTraverseNodeTraverser;
use Rector\Tests\AbstractContainerAwareTestCase;
@ -42,7 +43,7 @@ final class PropertyTest extends AbstractContainerAwareTestCase
{
/** @var PropertyFetch $propertyFetchNode */
$propertyFetchNode = $this->nodes[1]->stmts[1]->stmts[2]->stmts[0]->expr;
$this->assertSame(Html::class, $propertyFetchNode->getAttribute('type'));
$this->assertSame(Html::class, $propertyFetchNode->getAttribute(Attribute::TYPE));
}
/**
@ -50,8 +51,9 @@ final class PropertyTest extends AbstractContainerAwareTestCase
*/
public function testProperty(): void
{
/** @var Node $propertyNode */
$propertyNode = $this->nodes[1]->stmts[1]->stmts[0];
$this->assertSame(Html::class, $propertyNode->getAttribute('type'));
$this->assertSame(Html::class, $propertyNode->getAttribute(Attribute::TYPE));
}
/**
@ -59,7 +61,8 @@ final class PropertyTest extends AbstractContainerAwareTestCase
*/
public function testMethodParameter(): void
{
/** @var Node $constructorVariableNode */
$constructorVariableNode = $this->nodes[1]->stmts[1]->stmts[1]->params[0]->var;
$this->assertSame(Html::class, $constructorVariableNode->getAttribute('type'));
$this->assertSame(Html::class, $constructorVariableNode->getAttribute(Attribute::TYPE));
}
}

View File

@ -6,6 +6,7 @@ use Nette\Utils\Html;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use Rector\Contract\Parser\ParserInterface;
use Rector\Node\Attribute;
use Rector\NodeTraverser\StandaloneTraverseNodeTraverser;
use Rector\Tests\AbstractContainerAwareTestCase;
@ -42,7 +43,7 @@ final class VariableTest extends AbstractContainerAwareTestCase
{
/** @var Variable $htmlVariableNode */
$htmlVariableNode = $this->nodes[1]->stmts[1]->stmts[0]->stmts[0]->expr->var;
$this->assertSame(Html::class, $htmlVariableNode->getAttribute('type'));
$this->assertSame(Html::class, $htmlVariableNode->getAttribute(Attribute::TYPE));
}
/**
@ -52,6 +53,6 @@ final class VariableTest extends AbstractContainerAwareTestCase
{
/** @var Variable $assignedVariableNode */
$assignedVariableNode = $this->nodes[1]->stmts[1]->stmts[0]->stmts[1]->expr->var;
$this->assertSame(Html::class, $assignedVariableNode->getAttribute('type'));
$this->assertSame(Html::class, $assignedVariableNode->getAttribute(Attribute::TYPE));
}
}

View File

@ -2,13 +2,14 @@
namespace Rector\TriggerExtractor;
use Exception;
use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\MagicConst\Method;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Exception\NotImplementedException;
use Rector\Node\Attribute;
final class TriggerMessageResolver
{
@ -32,15 +33,15 @@ final class TriggerMessageResolver
if ($node instanceof Method) {
$classMethodNode = $this->findParentOfType($node, ClassMethod::class);
return $node->getAttribute('class') . '::' . $classMethodNode->name->name;
return $node->getAttribute(Attribute::CLASS_NAME) . '::' . $classMethodNode->name->name;
}
if ($node instanceof String_) {
$message = $node->value; // complet class to local methods
return $this->completeClassToLocalMethods($message, $node->getAttribute('class'));
return $this->completeClassToLocalMethods($message, (string) $node->getAttribute(Attribute::CLASS_NAME));
}
throw new Exception(sprintf(
throw new NotImplementedException(sprintf(
'Not implemented yet. Go to "%s::%s()" and add check for "%s" node.',
__CLASS__,
__METHOD__,
@ -50,10 +51,10 @@ final class TriggerMessageResolver
private function findParentOfType(Node $node, string $type): Node
{
$parentNode = $node->getAttribute('parent');
$parentNode = $node->getAttribute(Attribute::PARENT_NODE);
while (! is_a($parentNode, $type, true)) {
$parentNode = $parentNode->getAttribute('parent');
$parentNode = $parentNode->getAttribute(Attribute::PARENT_NODE);
}
return $parentNode;

View File

@ -0,0 +1,9 @@
<?php declare(strict_types=1);
namespace Rector\Exception;
use Exception;
final class NotImplementedException extends Exception
{
}

53
src/Node/Attribute.php Normal file
View File

@ -0,0 +1,53 @@
<?php declare(strict_types=1);
namespace Rector\Node;
/**
* List of attributes by constants, to prevent any typos.
*
* Because typo can causing return "null" instaed of real value - impossible to spot.
*/
final class Attribute
{
/**
* @var string
*/
public const TYPE = 'type';
/**
* System name to be found in @see \PhpParser\NodeVisitor\NameResolver
* Do not change this even if you want!
*
* @var string
*/
public const RESOLVED_NAME = 'resolvedName';
/**
* @var string
*/
public const CLASS_NAME = 'class';
/**
* @var string
*/
public const CLASS_NODE = 'class_node';
/**
* @var string
*/
public const PARENT_NODE = 'parent_node';
/**
* @var string
*/
public const PREVIOUS_NODE = 'prev_node';
/**
* @var string
*/
public const NEXT_NODE = 'next_node';
private function __construct()
{
}
}

View File

@ -1,52 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
final class ClassResolver
{
/**
* @var Class_|null
*/
private $classNode;
/**
* @param Node[] $nodes
*/
public function resolveFromNodes(array $nodes): void
{
$this->classNode = null;
foreach ($nodes as $node) {
if ($node instanceof Class_) {
$this->classNode = $node;
break;
}
}
}
public function getClassName(): string
{
if ($this->classNode === null) {
return '';
}
return $this->classNode->namespacedName->toString();
}
public function getParentClassName(): string
{
if ($this->classNode === null) {
return '';
}
$parentClass = $this->classNode->extends;
/** @var Node\Name\FullyQualified $fqnParentClassName */
$fqnParentClassName = $parentClass->getAttribute('resolvedName');
return $fqnParentClassName->toString();
}
}

View File

@ -5,6 +5,7 @@ namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Node\Attribute;
final class MethodCallAnalyzer
{
@ -72,10 +73,10 @@ final class MethodCallAnalyzer
{
$varNode = $methodCallNode->var;
while ($varNode->getAttribute('type') === null) {
while ($varNode->getAttribute(Attribute::TYPE) === null) {
$varNode = $varNode->var;
}
return (string) $varNode->getAttribute('type');
return (string) $varNode->getAttribute(Attribute::TYPE);
}
}

View File

@ -2,6 +2,7 @@
namespace Rector\NodeFactory;
use Nette\NotImplementedException;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
@ -31,16 +32,25 @@ final class NodeFactory
return new PropertyFetch($localVariable, $propertyName);
}
/**
* Creates "null"
*/
public function createNullConstant(): ConstFetch
{
return new ConstFetch(new Name('null'));
}
/**
* Creates "false"
*/
public function createFalseConstant(): ConstFetch
{
return new ConstFetch(new Name('false'));
}
/**
* Creates "SomeClass::CONSTANT"
*/
public function createClassConstant(string $className, string $constantName): ClassConstFetch
{
$classNameNode = new FullyQualified($className);
@ -48,6 +58,9 @@ final class NodeFactory
return new ClassConstFetch($classNameNode, $constantName);
}
/**
* Creates "SomeClass::class"
*/
public function createClassConstantReference(string $className): ClassConstFetch
{
$nameNode = new FullyQualified($className);
@ -55,6 +68,9 @@ final class NodeFactory
return new ClassConstFetch($nameNode, 'class');
}
/**
* Creates "$method->call();"
*/
public function createMethodCall(string $variableName, string $methodName): MethodCall
{
$varNode = new Variable($variableName);
@ -62,6 +78,9 @@ final class NodeFactory
return new MethodCall($varNode, $methodName);
}
/**
* Creates "use \SomeTrait;"
*/
public function createTraitUse(string $traitName): TraitUse
{
$traitNameNode = new FullyQualified($traitName);
@ -70,6 +89,8 @@ final class NodeFactory
}
/**
* Creates "['item', $variable]"
*
* @param mixed|Node[] ...$items
*/
public function createArray(...$items): Array_
@ -82,6 +103,13 @@ final class NodeFactory
} elseif ($item instanceof Identifier) {
$string = new String_((string) $item);
$arrayItems[] = new ArrayItem($string);
} else {
throw new NotImplementedException(sprintf(
'Not implemented yet. Go to "%s::%s()" and add check for "%s" node.',
__CLASS__,
__METHOD__,
get_class($item)
));
}
}
@ -91,6 +119,8 @@ final class NodeFactory
}
/**
* Creates "($args)"
*
* @param mixed[] $arguments
* @return Arg[]
*/

View File

@ -4,6 +4,7 @@ namespace Rector\NodeVisitor;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use Rector\Node\Attribute;
/**
* See https://github.com/nikic/PHP-Parser/blob/master/doc/5_FAQ.markdown#how-can-the-nextprevious-sibling-of-a-node-be-obtained.
@ -32,12 +33,14 @@ final class NodeConnector extends NodeVisitorAbstract
public function enterNode(Node $node): void
{
if (! empty($this->stack)) {
$node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
$node->setAttribute(Attribute::PARENT_NODE, $this->stack[count($this->stack) - 1]);
}
if ($this->prev && $this->prev->getAttribute('parent') === $node->getAttribute('parent')) {
$node->setAttribute('prev', $this->prev);
$this->prev->setAttribute('next', $node);
if ($this->prev &&
$this->prev->getAttribute(Attribute::PARENT_NODE) === $node->getAttribute(Attribute::PARENT_NODE)
) {
$node->setAttribute(Attribute::PREVIOUS_NODE, $this->prev);
$this->prev->setAttribute(Attribute::NEXT_NODE, $node);
}
$this->stack[] = $node;

View File

@ -7,6 +7,7 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use Rector\Node\Attribute;
abstract class AbstractChangeMethodNameRector extends AbstractRector
{
@ -65,7 +66,7 @@ abstract class AbstractChangeMethodNameRector extends AbstractRector
}
/** @var string $type */
$type = $node->var->getAttribute('type');
$type = $node->var->getAttribute(Attribute::TYPE);
if (! $this->isTypeRelevant($type)) {
return false;

View File

@ -5,6 +5,7 @@ namespace Rector\Rector;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use Rector\Node\Attribute;
abstract class AbstractChangeParentClassRector extends AbstractRector
{
@ -15,7 +16,7 @@ abstract class AbstractChangeParentClassRector extends AbstractRector
}
/** @var FullyQualified $fqnName */
$fqnName = $node->extends->getAttribute('resolvedName');
$fqnName = $node->extends->getAttribute(Attribute::RESOLVED_NAME);
return $fqnName->toString() === $this->getOldClassName();
}

View File

@ -3,29 +3,24 @@
namespace Rector\Rector\Contrib\Nette;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\Contract\Deprecation\DeprecationInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
/**
* Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject.
*/
final class FormCallbackRector extends NodeVisitorAbstract implements DeprecationInterface, RectorInterface
final class FormCallbackRector extends AbstractRector
{
/**
* @var string
*/
public const FORM_CLASS = 'Nette\Application\UI\Form';
/**
* @var Node
*/
private $previousNode;
/**
* @var NodeFactory
*/
@ -47,52 +42,47 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
}
/**
* @return null|int|Node
* Detects "$form->onSuccess[] = $this->someAction;"
*/
public function enterNode(Node $node)
{
if ($this->previousNode && $this->isFormEventAssign($this->previousNode)) {
if (! $node instanceof PropertyFetch) {
return null;
}
return $this->nodeFactory->createArray($node->var, $node->name);
}
$this->previousNode = $node;
if ($this->isFormEventAssign($node)) {
// do not check children, just go to next token
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
}
return null;
}
public function isCandidate(Node $node): bool
{
if (! $node instanceof Assign) {
return false;
}
if (! $node->var instanceof ArrayDimFetch) {
return false;
}
if (! $this->isFormEventHandler($node->var->var)) {
return false;
}
if (! $node->expr instanceof PropertyFetch) {
return false;
}
return true;
}
/**
* @param Assign $node
*/
public function refactor(Node $node): ?Node
{
$node->expr = $this->nodeFactory->createArray($node->expr->var, $node->expr->name);
return $node;
}
private function isFormEventAssign(Node $node): bool
private function isFormEventHandler(PropertyFetch $propertyFetchNode): bool
{
if (! $node instanceof PropertyFetch) {
if ($propertyFetchNode->var->getAttribute(Attribute::TYPE) !== self::FORM_CLASS) {
return false;
}
if ($node->var->getAttribute('type') !== self::FORM_CLASS) {
return false;
}
$propertyName = (string) $propertyFetchNode->name;
$propertyName = (string) $node->name;
if (! in_array($propertyName, ['onSuccess', 'onSubmit'], true)) {
return false;
}
return true;
return in_array($propertyName, ['onSuccess', 'onSubmit', 'onError', 'onRender'], true);
}
}

View File

@ -6,6 +6,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeAnalyzer\MethodCallAnalyzer;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -62,7 +63,7 @@ final class FormSetRequiredRector extends AbstractRector
return false;
}
if ($arg->value->class->getAttribute('type') !== self::FORM_CLASS) {
if ($arg->value->class->getAttribute(Attribute::TYPE) !== self::FORM_CLASS) {
return false;
}

View File

@ -0,0 +1,29 @@
<?php declare(strict_types=1);
namespace Rector\Rector\Contrib\Nette;
use Rector\Deprecation\SetNames;
use Rector\Rector\AbstractClassReplacerRector;
final class NetteConfiguratorRector extends AbstractClassReplacerRector
{
public function getSetName(): string
{
return SetNames::NETTE;
}
public function sinceVersion(): float
{
return 2.1;
}
/**
* @return string[]
*/
protected function getOldToNewClasses(): array
{
return [
'Nette\Config\Configurator' => 'Nette\Configurator',
];
}
}

View File

@ -7,6 +7,7 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use Rector\Builder\StatementGlue;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -58,7 +59,7 @@ final class NetteObjectToSmartTraitRector extends AbstractRector
}
/** @var FullyQualified $fqnName */
$fqnName = $node->extends->getAttribute('resolvedName');
$fqnName = $node->extends->getAttribute(Attribute::RESOLVED_NAME);
return $fqnName->toString() === self::PARENT_CLASS;
}

View File

@ -6,6 +6,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Scalar\String_;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\Rector\AbstractRector;
final class RemoveConfiguratorConstantsRector extends AbstractRector
@ -50,7 +51,7 @@ final class RemoveConfiguratorConstantsRector extends AbstractRector
private function getClassNameFromClassConstFetch(ClassConstFetch $classConstFetchNode): string
{
/** @var Node\Name\FullyQualified $fqnName */
$fqnName = $classConstFetchNode->class->getAttribute('resolvedName');
$fqnName = $classConstFetchNode->class->getAttribute(Attribute::RESOLVED_NAME);
return $fqnName->toString();
}

View File

@ -6,6 +6,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Scalar\String_;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -55,7 +56,7 @@ final class ConstraintUrlOptionRector extends AbstractRector
return false;
}
$prevNode = $node->getAttribute('prev');
$prevNode = $node->getAttribute(Attribute::PREVIOUS_NODE);
if (! $prevNode instanceof String_) {
return false;
}

View File

@ -6,6 +6,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\MethodCall;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -44,7 +45,7 @@ final class FormIsValidRector extends AbstractRector
return false;
}
if ($node->var->getAttribute('type') !== 'Symfony\Component\Form\Form') {
if ($node->var->getAttribute(Attribute::TYPE) !== 'Symfony\Component\Form\Form') {
return false;
}
@ -52,7 +53,7 @@ final class FormIsValidRector extends AbstractRector
return false;
}
if ($node->getAttribute('prev') !== null) {
if ($node->getAttribute(Attribute::PREVIOUS_NODE) !== null) {
return false;
}

View File

@ -10,6 +10,7 @@ use Rector\Builder\Class_\ClassPropertyCollector;
use Rector\Builder\Kernel\ServiceFromKernelResolver;
use Rector\Builder\Naming\NameResolver;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeAnalyzer\SymfonyContainerCallsAnalyzer;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -56,6 +57,7 @@ final class CommandToConstructorInjectionRector extends AbstractRector
* @var NodeFactory
*/
private $nodeFactory;
/**
* @var SymfonyContainerCallsAnalyzer
*/
@ -87,7 +89,7 @@ final class CommandToConstructorInjectionRector extends AbstractRector
public function isCandidate(Node $node): bool
{
$class = (string) $node->getAttribute('class');
$class = (string) $node->getAttribute(Attribute::CLASS_NAME);
if (! Strings::endsWith($class, 'Command')) {
return false;
@ -119,7 +121,7 @@ final class CommandToConstructorInjectionRector extends AbstractRector
$propertyName = $this->nameResolver->resolvePropertyNameFromType($serviceType);
$this->classPropertyCollector->addPropertyForClass(
(string) $node->getAttribute('class'),
(string) $node->getAttribute(Attribute::CLASS_NAME),
$serviceType,
$propertyName
);
@ -129,7 +131,7 @@ final class CommandToConstructorInjectionRector extends AbstractRector
private function replaceParentContainerAwareCommandWithCommand(Node $node): void
{
$classNode = $node->getAttribute('class_node');
$classNode = $node->getAttribute(Attribute::CLASS_NODE);
$classNode->extends = new FullyQualified('Symfony\Component\Console\Command\Command');
}
}

View File

@ -8,6 +8,7 @@ use Rector\Builder\Class_\ClassPropertyCollector;
use Rector\Builder\Kernel\ServiceFromKernelResolver;
use Rector\Builder\Naming\NameResolver;
use Rector\Deprecation\SetNames;
use Rector\Node\Attribute;
use Rector\NodeAnalyzer\SymfonyContainerCallsAnalyzer;
use Rector\NodeFactory\NodeFactory;
use Rector\Rector\AbstractRector;
@ -41,6 +42,7 @@ final class GetterToPropertyRector extends AbstractRector
* @var NodeFactory
*/
private $nodeFactory;
/**
* @var SymfonyContainerCallsAnalyzer
*/
@ -86,7 +88,7 @@ final class GetterToPropertyRector extends AbstractRector
$propertyName = $this->nameResolver->resolvePropertyNameFromType($serviceType);
$this->classPropertyCollector->addPropertyForClass(
(string) $methodCallNode->getAttribute('class'),
(string) $methodCallNode->getAttribute(Attribute::CLASS_NAME),
$serviceType,
$propertyName
);

View File

@ -14,6 +14,7 @@ services:
# PSR-4 autodiscovery
Rector\:
resource: '../../src'
exclude: '../../src/{Node/Attribute.php}'
# autowire by interface
Rector\Contract\Parser\ParserInterface:

View File

@ -0,0 +1,3 @@
<?php declare (strict_types=1);
$configurator = new \Nette\Configurator;

View File

@ -0,0 +1,25 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\Contrib\Nette\NetteConfiguratorRector;
use Rector\Rector\Contrib\Nette\NetteConfiguratorRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class Test extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFileMatchesExpectedContent(
__DIR__ . '/Wrong/wrong.php.inc',
__DIR__ . '/Correct/correct.php.inc'
);
}
/**
* @return string[]
*/
protected function getRectorClasses(): array
{
return [NetteConfiguratorRector::class];
}
}

View File

@ -0,0 +1,3 @@
<?php declare (strict_types=1);
$configurator = new Nette\Config\Configurator;