mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 08:20:53 +00:00
Updated Rector to commit 37b06023b6
37b06023b6
[DeadCode] Fix removal of variable-used promoted property (#593)
This commit is contained in:
parent
02eff0b257
commit
4be28bf7eb
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\DeadCode\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\NodeManipulator\PropertyManipulator;
|
||||
|
@ -86,21 +87,24 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
foreach ($node->getParams() as $param) {
|
||||
if ($param->flags === 0) {
|
||||
// only private local scope; removing public property might be dangerous
|
||||
if ($param->flags !== \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE) {
|
||||
continue;
|
||||
}
|
||||
if ($this->propertyManipulator->isPropertyUsedInReadContext($param)) {
|
||||
continue;
|
||||
}
|
||||
// only private local scope; removing public property might be dangerous
|
||||
if ($param->flags !== \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE) {
|
||||
continue;
|
||||
}
|
||||
$paramName = $this->getName($param);
|
||||
$propertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $paramName);
|
||||
if ($propertyFetches !== []) {
|
||||
continue;
|
||||
}
|
||||
// is variable used? only remove property, keep param
|
||||
$variable = $this->betterNodeFinder->findVariableOfName((array) $node->stmts, $paramName);
|
||||
if ($variable instanceof \PhpParser\Node\Expr\Variable) {
|
||||
$param->flags = 0;
|
||||
continue;
|
||||
}
|
||||
// remove param
|
||||
$this->removeNode($param);
|
||||
}
|
||||
|
|
|
@ -47,11 +47,6 @@ final class VariableNaming
|
|||
$this->valueResolver = $valueResolver;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
// public function resolveFromNode(Node $node): ?string
|
||||
// {
|
||||
// $nodeType = $this->nodeTypeResolver->getStaticType($node);
|
||||
// return $this->resolveFromNodeAndType($node, $nodeType);
|
||||
// }
|
||||
public function resolveFromNodeAndType(\PhpParser\Node $node, \PHPStan\Type\Type $type) : ?string
|
||||
{
|
||||
$variableName = $this->resolveBareFromNode($node);
|
||||
|
@ -101,22 +96,6 @@ final class VariableNaming
|
|||
$bareName = $this->resolveBareFuncCallArgumentName($funcCall, $fallbackName, $suffix);
|
||||
return $this->createCountedValueName($bareName, $scope);
|
||||
}
|
||||
// private function resolveFromNodeAndType(Node $node, Type $type): ?string
|
||||
// {
|
||||
// $variableName = $this->resolveBareFromNode($node);
|
||||
// if ($variableName === null) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // adjust static to specific class
|
||||
// if ($variableName === 'this' && $type instanceof ThisType) {
|
||||
// $shortClassName = $this->nodeNameResolver->getShortName($type->getClassName());
|
||||
// $variableName = lcfirst($shortClassName);
|
||||
// }
|
||||
//
|
||||
// $stringy = new Stringy($variableName);
|
||||
// return (string) $stringy->camelize();
|
||||
// }
|
||||
public function resolveFromNode(\PhpParser\Node $node) : ?string
|
||||
{
|
||||
$nodeType = $this->nodeTypeResolver->getStaticType($node);
|
||||
|
@ -152,22 +131,6 @@ final class VariableNaming
|
|||
}
|
||||
return null;
|
||||
}
|
||||
// private function unwrapNode(Node $node): ?Node
|
||||
// {
|
||||
// if ($node instanceof Arg) {
|
||||
// return $node->value;
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof Cast) {
|
||||
// return $node->expr;
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof Ternary) {
|
||||
// return $node->if;
|
||||
// }
|
||||
//
|
||||
// return $node;
|
||||
// }
|
||||
private function resolveParamNameFromArrayDimFetch(\PhpParser\Node\Expr\ArrayDimFetch $arrayDimFetch) : ?string
|
||||
{
|
||||
while ($arrayDimFetch instanceof \PhpParser\Node\Expr\ArrayDimFetch) {
|
||||
|
@ -232,108 +195,6 @@ final class VariableNaming
|
|||
}
|
||||
return $node;
|
||||
}
|
||||
// private function resolveParamNameFromArrayDimFetch(ArrayDimFetch $arrayDimFetch): ?string
|
||||
// {
|
||||
// while ($arrayDimFetch instanceof ArrayDimFetch) {
|
||||
// if ($arrayDimFetch->dim instanceof Scalar) {
|
||||
// $valueName = $this->nodeNameResolver->getName($arrayDimFetch->var);
|
||||
// $dimName = $this->valueResolver->getValue($arrayDimFetch->dim);
|
||||
//
|
||||
// $stringy = new Stringy($dimName);
|
||||
// $dimName = (string) $stringy->upperCamelize();
|
||||
//
|
||||
// return $valueName . $dimName;
|
||||
// }
|
||||
//
|
||||
// $arrayDimFetch = $arrayDimFetch->var;
|
||||
// }
|
||||
//
|
||||
// return $this->resolveBareFromNode($arrayDimFetch);
|
||||
// }
|
||||
// private function resolveBareFromNode(Node $node): ?string
|
||||
// {
|
||||
// $node = $this->unwrapNode($node);
|
||||
//
|
||||
// if ($node instanceof ArrayDimFetch) {
|
||||
// return $this->resolveParamNameFromArrayDimFetch($node);
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof PropertyFetch) {
|
||||
// return $this->resolveFromPropertyFetch($node);
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof MethodCall || $node instanceof NullsafeMethodCall || $node instanceof StaticCall) {
|
||||
// return $this->resolveFromMethodCall($node);
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof New_) {
|
||||
// return $this->resolveFromNew($node);
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof FuncCall) {
|
||||
// return $this->resolveFromNode($node->name);
|
||||
// }
|
||||
//
|
||||
// if (! $node instanceof Node) {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
//
|
||||
// $paramName = $this->nodeNameResolver->getName($node);
|
||||
// if ($paramName !== null) {
|
||||
// return $paramName;
|
||||
// }
|
||||
//
|
||||
// if ($node instanceof String_) {
|
||||
// return $node->value;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
// private function resolveFromNew(New_ $new): string
|
||||
// {
|
||||
// if ($new->class instanceof Name) {
|
||||
// $className = $this->nodeNameResolver->getName($new->class);
|
||||
// return $this->nodeNameResolver->getShortName($className);
|
||||
// }
|
||||
//
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param MethodCall|NullsafeMethodCall|StaticCall $node
|
||||
// */
|
||||
// private function resolveFromMethodCall(Node $node): ?string
|
||||
// {
|
||||
// if ($node->name instanceof MethodCall) {
|
||||
// return $this->resolveFromMethodCall($node->name);
|
||||
// }
|
||||
//
|
||||
// $methodName = $this->nodeNameResolver->getName($node->name);
|
||||
// if (! is_string($methodName)) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return $methodName;
|
||||
// }
|
||||
//
|
||||
// private function resolveFromPropertyFetch(PropertyFetch $propertyFetch): string
|
||||
// {
|
||||
// $varName = $this->nodeNameResolver->getName($propertyFetch->var);
|
||||
// if (! is_string($varName)) {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
//
|
||||
// $propertyName = $this->nodeNameResolver->getName($propertyFetch->name);
|
||||
// if (! is_string($propertyName)) {
|
||||
// throw new NotImplementedYetException();
|
||||
// }
|
||||
//
|
||||
// if ($varName === 'this') {
|
||||
// return $propertyName;
|
||||
// }
|
||||
//
|
||||
// return $varName . ucfirst($propertyName);
|
||||
// }
|
||||
private function resolveBareFuncCallArgumentName(\PhpParser\Node\Expr\FuncCall $funcCall, string $fallbackName, string $suffix) : string
|
||||
{
|
||||
$argumentValue = $funcCall->args[0]->value;
|
||||
|
|
|
@ -75,10 +75,6 @@ CODE_SAMPLE
|
|||
return new \PhpParser\Node\Expr\Assign($secondArrayItem->value, $currentFuncCall);
|
||||
}
|
||||
// both: list($key, $value) = each($values);
|
||||
// ↓
|
||||
// $key = key($values);
|
||||
// $value = current($values);
|
||||
// next($values);
|
||||
$currentFuncCall = $this->nodeFactory->createFuncCall('current', $eachFuncCall->args);
|
||||
$secondArrayItem = $listNode->items[1];
|
||||
if (!$secondArrayItem instanceof \PhpParser\Node\Expr\ArrayItem) {
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '1f538c68717d8f04896c6c7a17ff9f761f230612';
|
||||
public const PACKAGE_VERSION = '37b06023b666cac8ec2997e8e1605f93c25d3b6f';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-08-04 10:45:17';
|
||||
public const RELEASE_DATE = '2021-08-04 15:37:55';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210804\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
|
@ -135,27 +135,6 @@ final class BetterNodeFinder
|
|||
{
|
||||
return (bool) $this->findVariableOfName($nodes, $name);
|
||||
}
|
||||
// /**
|
||||
// * @param Node|Stmt[] $nodes
|
||||
// * @return Variable[]
|
||||
// */
|
||||
// public function findVariablesOfName(Node | array $nodes, string $variableName): array
|
||||
// {
|
||||
// /** @var Variable[] $variables */
|
||||
// $variables = $this->findInstanceOf($nodes, Variable::class);
|
||||
//
|
||||
// $variablesOfName = [];
|
||||
//
|
||||
// foreach ($variables as $variable) {
|
||||
// if (! $this->nodeNameResolver->isName($variable, $variableName)) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// $variablesOfName[] = $variable;
|
||||
// }
|
||||
//
|
||||
// return $variablesOfName;
|
||||
// }
|
||||
/**
|
||||
* @param Node|Node[] $nodes
|
||||
* @return Variable|null
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d::getLoader();
|
||||
return ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2::getLoader();
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d
|
||||
class ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire3095cb7649474ff36b9dd8eea2e17a8d($fileIdentifier, $file);
|
||||
composerRequiree0327f03b09a1b2506dcbad127f3a7d2($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire3095cb7649474ff36b9dd8eea2e17a8d($fileIdentifier, $file)
|
||||
function composerRequiree0327f03b09a1b2506dcbad127f3a7d2($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d
|
||||
class ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3845,9 +3845,9 @@ class ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3095cb7649474ff36b9dd8eea2e17a8d::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite0327f03b09a1b2506dcbad127f3a7d2::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20210804\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d', false) && !interface_exists('ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d', false) && !trait_exists('ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d', false)) {
|
||||
spl_autoload_call('RectorPrefix20210804\ComposerAutoloaderInit3095cb7649474ff36b9dd8eea2e17a8d');
|
||||
if (!class_exists('ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2', false) && !interface_exists('ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2', false) && !trait_exists('ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2', false)) {
|
||||
spl_autoload_call('RectorPrefix20210804\ComposerAutoloaderInite0327f03b09a1b2506dcbad127f3a7d2');
|
||||
}
|
||||
if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) {
|
||||
spl_autoload_call('RectorPrefix20210804\AjaxLogin');
|
||||
|
@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210804\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire3095cb7649474ff36b9dd8eea2e17a8d')) {
|
||||
function composerRequire3095cb7649474ff36b9dd8eea2e17a8d() {
|
||||
return \RectorPrefix20210804\composerRequire3095cb7649474ff36b9dd8eea2e17a8d(...func_get_args());
|
||||
if (!function_exists('composerRequiree0327f03b09a1b2506dcbad127f3a7d2')) {
|
||||
function composerRequiree0327f03b09a1b2506dcbad127f3a7d2() {
|
||||
return \RectorPrefix20210804\composerRequiree0327f03b09a1b2506dcbad127f3a7d2(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user