mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-21 09:42:45 +01:00
[PHP 5.5] Fix StringToClass name whilst import
This commit is contained in:
parent
6ae80bc07a
commit
87448dfa37
@ -108,6 +108,8 @@ final class NameImporter
|
||||
return true;
|
||||
}
|
||||
|
||||
// namespace <name>
|
||||
// use <name>;
|
||||
if ($this->isNamespaceOrUseImportName($name)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace Rector\Legacy\Tests\Rector\FileSystem\FunctionToStaticMethodRector;
|
||||
|
||||
use Rector\Core\Testing\PHPUnit\AbstractFileSystemRectorTestCase;
|
||||
use Rector\Legacy\Rector\Node\FunctionToStaticMethodRector;
|
||||
use Rector\Legacy\Rector\FileSystem\FunctionToStaticMethodRector;
|
||||
|
||||
final class FunctionToStaticMethodRectorTest extends AbstractFileSystemRectorTestCase
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
use Rector\Core\Util\StaticRectorStrings;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\ClassExistenceStaticHelper;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
@ -117,7 +118,11 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ClassConstFetch(new FullyQualified($classLikeName), 'class');
|
||||
$name = new FullyQualified($classLikeName);
|
||||
/** @see \Rector\PostRector\Collector\UseNodesToAddCollector::isShortImported() */
|
||||
$name->setAttribute(AttributeKey::FILE_INFO, $node->getAttribute(AttributeKey::FILE_INFO));
|
||||
|
||||
return new ClassConstFetch($name, 'class');
|
||||
}
|
||||
|
||||
private function classLikeSensitiveExists(string $classLikeName): bool
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\FixtureImport;
|
||||
|
||||
class SkipImportOfJustReplacedClasses
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$class = 'Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source\SomeUser';
|
||||
$user = new $class;
|
||||
|
||||
$anotherClass = 'Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source\SomeSecurity\SomeUser';
|
||||
$user = new $anotherClass;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\FixtureImport;
|
||||
|
||||
use Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source\SomeUser;
|
||||
class SkipImportOfJustReplacedClasses
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$class = SomeUser::class;
|
||||
$user = new $class;
|
||||
|
||||
$anotherClass = \Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source\SomeSecurity\SomeUser::class;
|
||||
$user = new $anotherClass;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
|
||||
|
||||
final class ImportClassNameRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(string $file): void
|
||||
{
|
||||
$this->setParameter(Option::AUTO_IMPORT_NAMES, true);
|
||||
|
||||
$this->doTestFile($file);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureImport');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return StringClassNameToClassConstantRector::class;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source\SomeSecurity;
|
||||
|
||||
final class SomeUser
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector\Source;
|
||||
|
||||
final class SomeUser
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user