mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 00:10:51 +00:00
Updated Rector to commit 0013604ebd8bf101ca9bd013a56d7e831bcdf51e
0013604ebd
[DX] Remove RemoveJustPropertyFetchRector as used for one time job, not practical for general use (#4661)
This commit is contained in:
parent
aef03f3b69
commit
813a09001a
|
@ -1,4 +1,4 @@
|
|||
# 363 Rules Overview
|
||||
# 362 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
- [CodingStyle](#codingstyle) (30)
|
||||
|
||||
- [DeadCode](#deadcode) (42)
|
||||
- [DeadCode](#deadcode) (41)
|
||||
|
||||
- [EarlyReturn](#earlyreturn) (9)
|
||||
|
||||
|
@ -2688,29 +2688,6 @@ Remove assign of property, just for value assign
|
|||
|
||||
<br>
|
||||
|
||||
### RemoveJustPropertyFetchRector
|
||||
|
||||
Inline property fetch assign to a variable, that has no added value
|
||||
|
||||
- class: [`Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchRector`](../rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
private $name;
|
||||
|
||||
public function run()
|
||||
{
|
||||
- $name = $this->name;
|
||||
-
|
||||
- return $name;
|
||||
+ return $this->name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### RemoveNonExistingVarAnnotationRector
|
||||
|
||||
Removes non-existing `@var` annotations above the code
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DeadCode\Rector\StmtsAwareInterface;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchRector\RemoveJustPropertyFetchRectorTest
|
||||
*/
|
||||
final class RemoveJustPropertyFetchRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Inline property fetch assign to a variable, that has no added value', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
private $name;
|
||||
|
||||
public function run()
|
||||
{
|
||||
$name = $this->name;
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
private $name;
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [StmtsAwareInterface::class];
|
||||
}
|
||||
/**
|
||||
* @param StmtsAwareInterface $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$stmts = (array) $node->stmts;
|
||||
if ($stmts === []) {
|
||||
return null;
|
||||
}
|
||||
foreach ($stmts as $key => $stmt) {
|
||||
if (!$stmt instanceof Return_) {
|
||||
continue;
|
||||
}
|
||||
if (!$stmt->expr instanceof Variable) {
|
||||
continue;
|
||||
}
|
||||
$previousStmt = $stmts[$key - 1] ?? null;
|
||||
if (!$previousStmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
$propertyFetch = $this->matchVariableToPropertyFetchAssign($previousStmt, $stmt->expr);
|
||||
if (!$propertyFetch instanceof PropertyFetch) {
|
||||
continue;
|
||||
}
|
||||
$assignPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($previousStmt);
|
||||
// there is a @var tag on purpose, keep the assign
|
||||
if ($assignPhpDocInfo->getVarTagValueNode() instanceof VarTagValueNode) {
|
||||
continue;
|
||||
}
|
||||
unset($node->stmts[$key - 1]);
|
||||
$stmt->expr = $propertyFetch;
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function matchVariableToPropertyFetchAssign(Expression $expression, Variable $variable) : ?PropertyFetch
|
||||
{
|
||||
if (!$expression->expr instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
$assign = $expression->expr;
|
||||
if (!$assign->expr instanceof PropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
// keep property fetch nesting
|
||||
if ($assign->expr->var instanceof PropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
if (!$assign->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isPropertyFetchCallerNode($assign->expr)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($variable, $assign->var)) {
|
||||
return null;
|
||||
}
|
||||
return $assign->expr;
|
||||
}
|
||||
private function isPropertyFetchCallerNode(PropertyFetch $propertyFetch) : bool
|
||||
{
|
||||
// skip nodes as mostly used with public property fetches
|
||||
$propertyFetchCallerType = $this->getType($propertyFetch->var);
|
||||
if (!$propertyFetchCallerType instanceof ObjectType) {
|
||||
return \false;
|
||||
}
|
||||
$nodeObjectType = new ObjectType('PhpParser\\Node');
|
||||
return $nodeObjectType->isSuperTypeOf($propertyFetchCallerType)->yes();
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'f76d034bf8eb60e7a7a2d73b2239aebf81b1ac51';
|
||||
public const PACKAGE_VERSION = '0013604ebd8bf101ca9bd013a56d7e831bcdf51e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-05 18:53:37';
|
||||
public const RELEASE_DATE = '2023-08-06 00:32:48';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInita2c899aec318d516f15998c8405c3588::getLoader();
|
||||
return ComposerAutoloaderInit14fb859f619c3158c7cf565c9a356221::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1714,7 +1714,6 @@ return array(
|
|||
'Rector\\DeadCode\\Rector\\StaticCall\\RemoveParentCallWithoutParentRector' => $baseDir . '/rules/DeadCode/Rector/StaticCall/RemoveParentCallWithoutParentRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Stmt\\RemoveUnreachableStatementRector' => $baseDir . '/rules/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector.php',
|
||||
'Rector\\DeadCode\\Rector\\StmtsAwareInterface\\RemoveJustPropertyFetchForAssignRector' => $baseDir . '/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchForAssignRector.php',
|
||||
'Rector\\DeadCode\\Rector\\StmtsAwareInterface\\RemoveJustPropertyFetchRector' => $baseDir . '/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Switch_\\RemoveDuplicatedCaseInSwitchRector' => $baseDir . '/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Ternary\\TernaryToBooleanOrFalseToBooleanAndRector' => $baseDir . '/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php',
|
||||
'Rector\\DeadCode\\Rector\\TryCatch\\RemoveDeadTryCatchRector' => $baseDir . '/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php',
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInita2c899aec318d516f15998c8405c3588
|
||||
class ComposerAutoloaderInit14fb859f619c3158c7cf565c9a356221
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInita2c899aec318d516f15998c8405c3588
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInita2c899aec318d516f15998c8405c3588', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit14fb859f619c3158c7cf565c9a356221', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita2c899aec318d516f15998c8405c3588', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit14fb859f619c3158c7cf565c9a356221', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita2c899aec318d516f15998c8405c3588::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit14fb859f619c3158c7cf565c9a356221::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInita2c899aec318d516f15998c8405c3588::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit14fb859f619c3158c7cf565c9a356221::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInita2c899aec318d516f15998c8405c3588
|
||||
class ComposerStaticInit14fb859f619c3158c7cf565c9a356221
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1968,7 +1968,6 @@ class ComposerStaticInita2c899aec318d516f15998c8405c3588
|
|||
'Rector\\DeadCode\\Rector\\StaticCall\\RemoveParentCallWithoutParentRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/StaticCall/RemoveParentCallWithoutParentRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Stmt\\RemoveUnreachableStatementRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector.php',
|
||||
'Rector\\DeadCode\\Rector\\StmtsAwareInterface\\RemoveJustPropertyFetchForAssignRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchForAssignRector.php',
|
||||
'Rector\\DeadCode\\Rector\\StmtsAwareInterface\\RemoveJustPropertyFetchRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustPropertyFetchRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Switch_\\RemoveDuplicatedCaseInSwitchRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php',
|
||||
'Rector\\DeadCode\\Rector\\Ternary\\TernaryToBooleanOrFalseToBooleanAndRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php',
|
||||
'Rector\\DeadCode\\Rector\\TryCatch\\RemoveDeadTryCatchRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/TryCatch/RemoveDeadTryCatchRector.php',
|
||||
|
@ -3015,9 +3014,9 @@ class ComposerStaticInita2c899aec318d516f15998c8405c3588
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita2c899aec318d516f15998c8405c3588::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita2c899aec318d516f15998c8405c3588::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita2c899aec318d516f15998c8405c3588::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit14fb859f619c3158c7cf565c9a356221::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit14fb859f619c3158c7cf565c9a356221::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit14fb859f619c3158c7cf565c9a356221::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user