mirror of https://github.com/rectorphp/rector.git
make tests pass
This commit is contained in:
parent
7998094641
commit
28c672312b
|
@ -5,6 +5,9 @@ checkers:
|
|||
# order use statements A-Z
|
||||
- PhpCsFixer\Fixer\Import\OrderedImportsFixer
|
||||
|
||||
# remove leading slash ("\") at imports
|
||||
- PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer
|
||||
|
||||
# remove extra spaces from DocBlocks
|
||||
- PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
use PhpParser\Node\Stmt\UseUse;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeVisitor\Collector\NodeCollector;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
@ -19,32 +18,17 @@ final class ClassReplacerRector extends AbstractRector
|
|||
*/
|
||||
private $oldToNewClasses = [];
|
||||
|
||||
/**
|
||||
* @var NamespaceAnalyzer
|
||||
*/
|
||||
private $namespaceAnalyzer;
|
||||
|
||||
/**
|
||||
* @var NodeCollector
|
||||
*/
|
||||
private $nodeCollector;
|
||||
|
||||
/**
|
||||
* @param string[] $oldToNewClasses
|
||||
*/
|
||||
public function __construct(
|
||||
array $oldToNewClasses,
|
||||
NamespaceAnalyzer $namespaceAnalyzer,
|
||||
NodeCollector $nodeCollector
|
||||
) {
|
||||
public function __construct(array $oldToNewClasses)
|
||||
{
|
||||
$this->oldToNewClasses = $oldToNewClasses;
|
||||
$this->namespaceAnalyzer = $namespaceAnalyzer;
|
||||
$this->nodeCollector = $nodeCollector;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof Name && ! $node instanceof Use_) {
|
||||
if (! $node instanceof Name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,32 +41,16 @@ final class ClassReplacerRector extends AbstractRector
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Name|UseUse $node
|
||||
* @param Name $nameNode
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
public function refactor(Node $nameNode): ?Node
|
||||
{
|
||||
if ($node instanceof Name) {
|
||||
$newName = $this->resolveNewNameFromNode($node);
|
||||
if ($nameNode instanceof Name) {
|
||||
$newName = $this->resolveNewNameFromNode($nameNode);
|
||||
|
||||
return new FullyQualified($newName);
|
||||
}
|
||||
|
||||
if ($node instanceof Use_) {
|
||||
$newName = $this->resolveNewNameFromNode($node);
|
||||
|
||||
if ($this->namespaceAnalyzer->isUseStatementAlreadyPresent($node, $newName)) {
|
||||
$this->nodeCollector->addNodeToRemove($node);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->uses[0]->name = new Name($newName);
|
||||
|
||||
$node->setAttribute(Attribute::ORIGINAL_NODE, null);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,6 @@ final class Test extends AbstractConfigurableRectorTestCase
|
|||
__DIR__ . '/wrong/wrong3.php.inc',
|
||||
__DIR__ . '/correct/correct3.php.inc'
|
||||
);
|
||||
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong4.php.inc',
|
||||
__DIR__ . '/correct/correct4.php.inc'
|
||||
);
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Bagr;
|
||||
|
||||
use NewClass;
|
||||
class SomeClass
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Sonata Project package.
|
||||
*
|
||||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Sonata\CoreBundle\Twig\Extension;
|
||||
use Sonata\CoreBundle\FlashMessage\FlashManager;
|
||||
/**
|
||||
* This is the Sonata core flash message Twig extension.
|
||||
*
|
||||
* @author Vincent Composieux <composieux@ekino.com>
|
||||
*/
|
||||
class FlashMessageExtension extends \Twig\Extension\AbstractExtension
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
$newClass = new NewClass;
|
||||
|
||||
return new \NewClass;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use PhpParser\Builder\Method;
|
|||
use PhpParser\Builder\Param;
|
||||
use PhpParser\Builder\Property;
|
||||
use PhpParser\Builder\Trait_;
|
||||
use PhpParser\Builder;
|
||||
use \PhpParser\Builder;
|
||||
use PhpParser\BuilderFactory;
|
||||
use PhpParser\Comment\Doc;
|
||||
use PhpParser\Node\Const_;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the Sonata Project package.
|
||||
*
|
||||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Sonata\CoreBundle\Twig\Extension;
|
||||
use Sonata\CoreBundle\FlashMessage\FlashManager;
|
||||
/**
|
||||
* This is the Sonata core flash message Twig extension.
|
||||
*
|
||||
* @author Vincent Composieux <composieux@ekino.com>
|
||||
*/
|
||||
class FlashMessageExtension extends \Twig\Extension\AbstractExtension
|
||||
{
|
||||
|
||||
}
|
|
@ -1,17 +1,20 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
use Bagr;
|
||||
use OldClass;
|
||||
use NewClass;
|
||||
|
||||
class SomeClass
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Sonata Project package.
|
||||
*
|
||||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Sonata\CoreBundle\Twig\Extension;
|
||||
use Sonata\CoreBundle\FlashMessage\FlashManager;
|
||||
/**
|
||||
* This is the Sonata core flash message Twig extension.
|
||||
*
|
||||
* @author Vincent Composieux <composieux@ekino.com>
|
||||
*/
|
||||
class FlashMessageExtension extends \Twig_Extension
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
$newClass = new NewClass;
|
||||
|
||||
return new OldClass;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the Sonata Project package.
|
||||
*
|
||||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Sonata\CoreBundle\Twig\Extension;
|
||||
use Sonata\CoreBundle\FlashMessage\FlashManager;
|
||||
/**
|
||||
* This is the Sonata core flash message Twig extension.
|
||||
*
|
||||
* @author Vincent Composieux <composieux@ekino.com>
|
||||
*/
|
||||
class FlashMessageExtension extends \Twig_Extension
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue