change PropertyRector to InjectPropertyRector

This commit is contained in:
TomasVotruba 2017-08-12 13:43:13 +02:00
parent 32b90c75c6
commit 5eedea88ae
3 changed files with 31 additions and 18 deletions

View File

@ -9,8 +9,16 @@ This tool will *reconstruct* (change) your code - **run it only in a new clean g
## All Reconstructors
- `InjectAnnotationToConstructorNodeTraverser` ([Nette](https://github.com/nette/))
- `NamedServicesToConstructorNodeTraverser` ([Symfony](https://github.com/symfony/))
### [Nette](https://github.com/nette/)
- `FormCallbackRector`
- `InjectPropertyRector`
- `NetteObjectToSmartTraitRector`
- `RemoveConfiguratorConstantsRector`
### [Symfony](https://github.com/symfony/)
- `NamedServicesToConstructorNodeTraverser`
## Install

View File

@ -13,7 +13,7 @@ use Rector\Contract\Deprecation\DeprecationInterface;
use Rector\Deprecation\SetNames;
/**
* Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject
* Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject.
*/
final class FormCallbackRector extends NodeVisitorAbstract implements DeprecationInterface
{
@ -80,9 +80,9 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
new String_(
(string) $node->name
)
)
),
], [
'kind' => Array_::KIND_SHORT
'kind' => Array_::KIND_SHORT,
]);
}
}

View File

@ -1,17 +1,18 @@
<?php declare(strict_types=1);
namespace Rector\NodeVisitor\DependencyInjection\InjectAnnotationToConstructor;
namespace Rector\Rector\Contrib\Nette;
use PhpCsFixer\DocBlock\DocBlock;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\NodeVisitorAbstract;
use Rector\Builder\Class_\ClassPropertyCollector;
use Rector\Deprecation\SetNames;
use Rector\NodeTraverser\TokenSwitcher;
use Rector\Rector\AbstractRector;
final class PropertyRector extends NodeVisitorAbstract
final class InjectPropertyRector extends AbstractRector
{
/**
* @var string
@ -56,15 +57,6 @@ final class PropertyRector extends NodeVisitorAbstract
return null;
}
public function enterNode(Node $node): ?Node
{
if (! $this->isCandidate($node)) {
return null;
}
return $this->reconstructProperty($node);
}
public function isCandidate(Node $node): bool
{
if (! $node instanceof Property) {
@ -80,7 +72,10 @@ final class PropertyRector extends NodeVisitorAbstract
return true;
}
private function reconstructProperty(Property $propertyNode): Property
/**
* @param Property $propertyNode
*/
public function refactor($propertyNode): Node
{
$propertyDocBlock = $this->createDocBlockFromNode($propertyNode);
$propertyNode = $this->removeInjectAnnotationFromProperty($propertyNode, $propertyDocBlock);
@ -92,6 +87,16 @@ final class PropertyRector extends NodeVisitorAbstract
return $propertyNode;
}
public function getSetName(): string
{
return SetNames::NETTE;
}
public function sinceVersion(): float
{
return 2.1;
}
private function hasInjectAnnotation(Property $propertyNode): bool
{
$propertyDocBlock = $this->createDocBlockFromNode($propertyNode);