Updated Rector to commit edd78eb310

edd78eb310 fix cs
This commit is contained in:
Tomas Votruba 2021-06-25 15:48:58 +00:00
parent 348ed1d016
commit 56f42aa88e
12 changed files with 146 additions and 44 deletions

View File

@ -93,4 +93,5 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector::class);
$services->set(\Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector::class);
$services->set(\Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector::class);
$services->set(\Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class);
};

View File

@ -8,28 +8,18 @@ use Rector\ChangesReporting\Annotation\RectorsChangelogResolver;
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
use Rector\Core\ValueObject\Configuration;
use Rector\Core\ValueObject\ProcessResult;
use RectorPrefix20210625\Symplify\SmartFileSystem\SmartFileSystem;
final class JsonOutputFormatter implements \Rector\ChangesReporting\Contract\Output\OutputFormatterInterface
{
/**
* @var string
*/
public const NAME = 'json';
/**
* @var \Symplify\SmartFileSystem\SmartFileSystem
*/
private $smartFileSystem;
/**
* @var \Rector\ChangesReporting\Annotation\RectorsChangelogResolver
*/
private $rectorsChangelogResolver;
public function __construct(
// @todo add rector for unused promoted property
\RectorPrefix20210625\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem,
\Rector\ChangesReporting\Annotation\RectorsChangelogResolver $rectorsChangelogResolver
)
public function __construct(\Rector\ChangesReporting\Annotation\RectorsChangelogResolver $rectorsChangelogResolver)
{
$this->smartFileSystem = $smartFileSystem;
$this->rectorsChangelogResolver = $rectorsChangelogResolver;
}
public function getName() : string

View File

@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use Rector\Core\NodeAnalyzer\CompactFuncCallAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer;
use Rector\DeadCode\NodeFinder\NextVariableUsageNodeFinder;
use Rector\DeadCode\NodeFinder\PreviousVariableAssignNodeFinder;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
@ -45,18 +44,13 @@ final class RemoveUnusedAssignVariableRector extends \Rector\Core\Rector\Abstrac
* @var \Rector\DeadCode\SideEffect\SideEffectNodeDetector
*/
private $sideEffectNodeDetector;
/**
* @var \Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer
*/
private $usedVariableNameAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\CompactFuncCallAnalyzer $compactFuncCallAnalyzer, \Rector\DeadCode\NodeFinder\NextVariableUsageNodeFinder $nextVariableUsageNodeFinder, \Rector\DeadCode\NodeFinder\PreviousVariableAssignNodeFinder $previousVariableAssignNodeFinder, \Rector\NodeNestingScope\ScopeNestingComparator $scopeNestingComparator, \Rector\DeadCode\SideEffect\SideEffectNodeDetector $sideEffectNodeDetector, \Rector\DeadCode\NodeAnalyzer\UsedVariableNameAnalyzer $usedVariableNameAnalyzer)
public function __construct(\Rector\Core\NodeAnalyzer\CompactFuncCallAnalyzer $compactFuncCallAnalyzer, \Rector\DeadCode\NodeFinder\NextVariableUsageNodeFinder $nextVariableUsageNodeFinder, \Rector\DeadCode\NodeFinder\PreviousVariableAssignNodeFinder $previousVariableAssignNodeFinder, \Rector\NodeNestingScope\ScopeNestingComparator $scopeNestingComparator, \Rector\DeadCode\SideEffect\SideEffectNodeDetector $sideEffectNodeDetector)
{
$this->compactFuncCallAnalyzer = $compactFuncCallAnalyzer;
$this->nextVariableUsageNodeFinder = $nextVariableUsageNodeFinder;
$this->previousVariableAssignNodeFinder = $previousVariableAssignNodeFinder;
$this->scopeNestingComparator = $scopeNestingComparator;
$this->sideEffectNodeDetector = $sideEffectNodeDetector;
$this->usedVariableNameAnalyzer = $usedVariableNameAnalyzer;
}
/**
* @return array<class-string<Node>>

View File

@ -0,0 +1,102 @@
<?php
declare (strict_types=1);
namespace Rector\DeadCode\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector\RemoveUnusedPromotedPropertyRectorTest
*/
final class RemoveUnusedPromotedPropertyRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder
*/
private $propertyFetchFinder;
public function __construct(\Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder $propertyFetchFinder)
{
$this->propertyFetchFinder = $propertyFetchFinder;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove unused promoted property', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(
private $someUnusedDependency,
private $usedDependency
) {
}
public function getUsedDependency()
{
return $this->usedDependency;
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(
private $usedDependency
) {
}
public function getUsedDependency()
{
return $this->usedDependency;
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if (!$this->isAtLeastPhpVersion(\Rector\Core\ValueObject\PhpVersionFeature::PROPERTY_PROMOTION)) {
return null;
}
if (!$this->isName($node, \Rector\Core\ValueObject\MethodName::CONSTRUCT)) {
return null;
}
$class = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE);
if (!$class instanceof \PhpParser\Node\Stmt\Class_) {
return null;
}
foreach ($node->getParams() as $param) {
if ($param->flags === 0) {
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;
}
// remove param
$this->removeNode($param);
}
return $node;
}
}

View File

@ -19,7 +19,6 @@ use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use Rector\Core\PHPStan\Reflection\CallReflectionResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\TypeDeclaration\NodeTypeAnalyzer\CallTypeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -27,17 +26,12 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class DowngradeNamedArgumentRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\TypeDeclaration\NodeTypeAnalyzer\CallTypeAnalyzer
*/
private $callTypeAnalyzer;
/**
* @var \Rector\Core\PHPStan\Reflection\CallReflectionResolver
*/
private $callReflectionResolver;
public function __construct(\Rector\TypeDeclaration\NodeTypeAnalyzer\CallTypeAnalyzer $callTypeAnalyzer, \Rector\Core\PHPStan\Reflection\CallReflectionResolver $callReflectionResolver)
public function __construct(\Rector\Core\PHPStan\Reflection\CallReflectionResolver $callReflectionResolver)
{
$this->callTypeAnalyzer = $callTypeAnalyzer;
$this->callReflectionResolver = $callReflectionResolver;
}
/**

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'c0758c29a9250cc16686e4d738a0b80381290b1b';
public const PACKAGE_VERSION = 'edd78eb3109e879ef3bf92ba0e678feb3f915d61';
/**
* @var string
*/
public const RELEASE_DATE = '2021-06-25 17:20:11';
public const RELEASE_DATE = '2021-06-25 17:38:19';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210625\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -59,4 +59,23 @@ final class PropertyFetchFinder
});
return $propertyFetches;
}
/**
* @return PropertyFetch[]
*/
public function findLocalPropertyFetchesByName(\PhpParser\Node\Stmt\Class_ $class, string $paramName) : array
{
/** @var PropertyFetch[] $propertyFetches */
$propertyFetches = $this->betterNodeFinder->findInstanceOf($class, \PhpParser\Node\Expr\PropertyFetch::class);
$foundPropertyFetches = [];
foreach ($propertyFetches as $propertyFetch) {
if (!$this->nodeNameResolver->isName($propertyFetch->var, 'this')) {
continue;
}
if (!$this->nodeNameResolver->isName($propertyFetch->name, $paramName)) {
continue;
}
$foundPropertyFetches[] = $propertyFetch;
}
return $foundPropertyFetches;
}
}

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c::getLoader();
return ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5::getLoader();

View File

@ -1965,6 +1965,7 @@ return array(
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedConstructorParamRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPrivateMethodParameterRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodParameterRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPrivateMethodRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPromotedPropertyRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUselessParamTagRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUselessReturnTagRector' => $baseDir . '/rules/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector.php',
'Rector\\DeadCode\\Rector\\Concat\\RemoveConcatAutocastRector' => $baseDir . '/rules/DeadCode/Rector/Concat/RemoveConcatAutocastRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c
class ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5', '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\ComposerStaticInitb34a3d95b98b707041b08962e8820f1c::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitb34a3d95b98b707041b08962e8820f1c::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireb34a3d95b98b707041b08962e8820f1c($fileIdentifier, $file);
composerRequire94d0aad65c05bb6d28c797ab723821f5($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequireb34a3d95b98b707041b08962e8820f1c($fileIdentifier, $file)
function composerRequire94d0aad65c05bb6d28c797ab723821f5($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitb34a3d95b98b707041b08962e8820f1c
class ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2320,6 +2320,7 @@ class ComposerStaticInitb34a3d95b98b707041b08962e8820f1c
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedConstructorParamRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedConstructorParamRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPrivateMethodParameterRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodParameterRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPrivateMethodRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUnusedPromotedPropertyRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPromotedPropertyRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUselessParamTagRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUselessParamTagRector.php',
'Rector\\DeadCode\\Rector\\ClassMethod\\RemoveUselessReturnTagRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector.php',
'Rector\\DeadCode\\Rector\\Concat\\RemoveConcatAutocastRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Concat/RemoveConcatAutocastRector.php',
@ -3869,9 +3870,9 @@ class ComposerStaticInitb34a3d95b98b707041b08962e8820f1c
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb34a3d95b98b707041b08962e8820f1c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb34a3d95b98b707041b08962e8820f1c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb34a3d95b98b707041b08962e8820f1c::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit94d0aad65c05bb6d28c797ab723821f5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -21,8 +21,8 @@ if (!class_exists('SomeTestCase', false) && !interface_exists('SomeTestCase', fa
if (!class_exists('CheckoutEntityFactory', false) && !interface_exists('CheckoutEntityFactory', false) && !trait_exists('CheckoutEntityFactory', false)) {
spl_autoload_call('RectorPrefix20210625\CheckoutEntityFactory');
}
if (!class_exists('ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c', false) && !interface_exists('ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c', false) && !trait_exists('ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c', false)) {
spl_autoload_call('RectorPrefix20210625\ComposerAutoloaderInitb34a3d95b98b707041b08962e8820f1c');
if (!class_exists('ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5', false) && !interface_exists('ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5', false) && !trait_exists('ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5', false)) {
spl_autoload_call('RectorPrefix20210625\ComposerAutoloaderInit94d0aad65c05bb6d28c797ab723821f5');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210625\Doctrine\Inflector\Inflector');
@ -3323,9 +3323,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210625\print_node(...func_get_args());
}
}
if (!function_exists('composerRequireb34a3d95b98b707041b08962e8820f1c')) {
function composerRequireb34a3d95b98b707041b08962e8820f1c() {
return \RectorPrefix20210625\composerRequireb34a3d95b98b707041b08962e8820f1c(...func_get_args());
if (!function_exists('composerRequire94d0aad65c05bb6d28c797ab723821f5')) {
function composerRequire94d0aad65c05bb6d28c797ab723821f5() {
return \RectorPrefix20210625\composerRequire94d0aad65c05bb6d28c797ab723821f5(...func_get_args());
}
}
if (!function_exists('parseArgs')) {