mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 17:00:51 +00:00
remove ClearReturnNewByReferenceRector, PHPStan cannot handle it
This commit is contained in:
parent
292cee48a2
commit
051c75131f
|
@ -20,7 +20,7 @@
|
|||
"nette/utils": "^3.2",
|
||||
"nikic/php-parser": "4.13.0",
|
||||
"phpstan/phpdoc-parser": "^1.2",
|
||||
"phpstan/phpstan": "1.0.x-dev as 0.12.99",
|
||||
"phpstan/phpstan": "^1.0",
|
||||
"phpstan/phpstan-phpunit": "^0.12.22",
|
||||
"rector/extension-installer": "^0.11.1",
|
||||
"rector/rector-cakephp": "^0.11.5",
|
||||
|
@ -56,7 +56,7 @@
|
|||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan-nette": "^0.12.21",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"rector/phpstan-rules": "^0.4.6",
|
||||
"rector/phpstan-rules": "^0.4.7",
|
||||
"rector/rector-generator": "^0.4.1",
|
||||
"spatie/enum": "^3.9",
|
||||
"symplify/coding-standard": "^9.5",
|
||||
|
@ -107,6 +107,7 @@
|
|||
"rules-tests/Renaming/Rector/Name/RenameClassRector/Source"
|
||||
],
|
||||
"files": [
|
||||
"rules-tests/CodeQuality/Rector/Name/FixClassCaseSensitivityNameRector/Source/MissCaseTypedClass.php",
|
||||
"stubs/Doctrine/Persistence/ObjectManager.php",
|
||||
"stubs/Doctrine/Common/Persistence/ObjectManager.php",
|
||||
"rules-tests/Transform/Rector/FuncCall/FuncCallToMethodCallRector/Source/some_view_function.php",
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php53\Rector\AssignRef\ClearReturnNewByReferenceRector;
|
||||
use Rector\Php53\Rector\FuncCall\DirNameFileConstantToDirConstantRector;
|
||||
use Rector\Php53\Rector\Ternary\TernaryToElvisRector;
|
||||
use Rector\Php53\Rector\Variable\ReplaceHttpServerVarsByServerRector;
|
||||
|
@ -10,11 +9,8 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
|||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(TernaryToElvisRector::class);
|
||||
|
||||
$services->set(DirNameFileConstantToDirConstantRector::class);
|
||||
|
||||
$services->set(ClearReturnNewByReferenceRector::class);
|
||||
|
||||
$services->set(ReplaceHttpServerVarsByServerRector::class);
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@ final class FixClassCaseSensitivityNameRectorTest extends AbstractRectorTestCase
|
|||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
// for PHPStan class reflection
|
||||
require_once __DIR__ . '/Source/MissCaseTypedClass.php';
|
||||
//require_once __DIR__ . '/Source/MissCaseTypedClass.php';
|
||||
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
|
|
@ -13,3 +13,24 @@ abstract class KeepStaticMethod
|
|||
return Token::create($parts[0] ?? '', $parts[1] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||
|
||||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture\Contract\Token;
|
||||
abstract class KeepStaticMethod
|
||||
{
|
||||
public static function decode(string $token): Token
|
||||
{
|
||||
$parts = explode('|', (string) base64_decode($token, true));
|
||||
|
||||
return Token::create($parts[0] ?? '', $parts[1] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,3 +11,18 @@ class SkipAliasedNames
|
|||
}
|
||||
}
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Blank;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class SkipAliasedNames
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$constraint = Blank::class;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -11,3 +11,18 @@ class SkipSameNamespacedUsedClass
|
|||
{
|
||||
}
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||
|
||||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\SharedShortName;
|
||||
class SkipSameNamespacedUsedClass
|
||||
{
|
||||
/**
|
||||
* @return SharedShortName
|
||||
*/
|
||||
public function run(): SharedShortName
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Php53\Rector\AssignRef\ClearReturnNewByReferenceRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use SplFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ClearReturnNewByReferenceRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SplFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
$instance = &new Foo();
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
$instance = new Foo();
|
||||
|
||||
?>
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Php53\Rector\AssignRef\ClearReturnNewByReferenceRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(ClearReturnNewByReferenceRector::class);
|
||||
};
|
|
@ -81,6 +81,7 @@ CODE_SAMPLE
|
|||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$fullyQualifiedName = $this->resolveFullyQualifiedName($node);
|
||||
|
||||
if (! $this->reflectionProvider->hasClass($fullyQualifiedName)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -91,6 +92,9 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
|
||||
dump($fullyQualifiedName);
|
||||
die;
|
||||
|
||||
$realClassName = $classReflection->getName();
|
||||
if (strtolower($realClassName) !== strtolower($fullyQualifiedName)) {
|
||||
// skip class alias
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php53\Rector\AssignRef;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\AssignRef;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see https://3v4l.org/UJN6H
|
||||
* @see \Rector\Tests\Php53\Rector\AssignRef\ClearReturnNewByReferenceRector\ClearReturnNewByReferenceRectorTest
|
||||
*/
|
||||
final class ClearReturnNewByReferenceRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
public function provideMinPhpVersion(): int
|
||||
{
|
||||
return PhpVersionFeature::NO_REFERENCE_IN_NEW;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Remove reference from "$assign = &new Value;"',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
$assign = &new Value;
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
$assign = new Value;
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [AssignRef::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AssignRef $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $node->expr instanceof New_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Assign($node->var, $node->expr);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user