mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
wip
This commit is contained in:
parent
23dde903b7
commit
7b03a0c30e
|
@ -11,5 +11,5 @@ interface RectorInterface
|
|||
/**
|
||||
* @param Node $node
|
||||
*/
|
||||
public function refactor($node): void;
|
||||
public function refactor($node): ?Node;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,16 @@ use Rector\Contract\Rector\RectorInterface;
|
|||
|
||||
abstract class AbstractRector extends NodeVisitorAbstract implements DeprecationInterface, RectorInterface
|
||||
{
|
||||
public function enterNode(Node $node): ?int
|
||||
/**
|
||||
* @return int|null|Node
|
||||
*/
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
if ($this->isCandidate($node)) {
|
||||
$this->refactor($node);
|
||||
if ($newNode = $this->refactor($node)) {
|
||||
return $newNode;
|
||||
}
|
||||
|
||||
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ final class FormCallbackRector extends NodeVisitorAbstract implements Deprecatio
|
|||
public function enterNode(Node $node): ?int
|
||||
{
|
||||
if ($this->isCandidate($node)) {
|
||||
return false;
|
||||
dump($node); // get next node!
|
||||
die;
|
||||
|
||||
|
|
|
@ -56,13 +56,15 @@ final class NetteObjectToSmartTraitRector extends AbstractRector
|
|||
/**
|
||||
* @param Class_ $classNode
|
||||
*/
|
||||
public function refactor($classNode): void
|
||||
public function refactor($classNode): ?Node
|
||||
{
|
||||
// remove parent class
|
||||
$classNode->extends = null;
|
||||
|
||||
$traitUseNode = $this->createTraitUse('Nette\SmartObject');
|
||||
$this->statementGlue->addAsFirstTrait($classNode, $traitUseNode);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function createTraitUse(string $traitName): TraitUse
|
||||
|
|
|
@ -6,13 +6,16 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use Rector\Deprecation\SetNames;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
final class RemoveConfiguratorConstantsRector extends AbstractRector
|
||||
{
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if ($node instanceof ClassConstFetch) {
|
||||
if ((string) $node->class !== 'Nette\Configurator') {
|
||||
// @todo: check FQN namespace
|
||||
$className = (string) $node->class;
|
||||
if (! in_array($className, ['Nette\Configurator', 'Configurator'], true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -29,12 +32,12 @@ final class RemoveConfiguratorConstantsRector extends AbstractRector
|
|||
/**
|
||||
* @param ClassConstFetch $classConstFetchNode
|
||||
*/
|
||||
public function refactor($classConstFetchNode): void
|
||||
public function refactor($classConstFetchNode): ?Node
|
||||
{
|
||||
dump($classConstFetchNode->name->name);
|
||||
die;
|
||||
$constantName = (string) $classConstFetchNode->name;
|
||||
$string = strtolower($constantName);
|
||||
|
||||
$classConstFetchNode->name->name = $this->getNewConstantName();
|
||||
return new String_($string);
|
||||
}
|
||||
|
||||
public function getSetName(): string
|
||||
|
|
|
@ -4,6 +4,6 @@ class ClassWithExternalConstant
|
|||
{
|
||||
public function getValue()
|
||||
{
|
||||
return ClassWithConstants::NEW_CONSTANT;
|
||||
return 'development';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
use Nette\Configurator;
|
||||
|
||||
class ClassWithExternalConstant
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return ClassWithConstants::OLD_CONSTANT;
|
||||
return Configurator::DEVELOPMENT;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user