mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 20:39:43 +01:00
Updated Rector to commit 22e97d1c418d0772cf449ed888522ca060829ddf
22e97d1c41
Cleanup stmts (#4027)
This commit is contained in:
parent
8fa5f13430
commit
010d5d2c6f
@ -5,7 +5,6 @@ namespace Rector\DeadCode\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Nop;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
|
||||
@ -79,8 +78,8 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
$hasRemoved = \false;
|
||||
foreach ($node->stmts as $key => $property) {
|
||||
$hasChanged = \false;
|
||||
foreach ($node->stmts as $property) {
|
||||
if (!$property instanceof Property) {
|
||||
continue;
|
||||
}
|
||||
@ -94,24 +93,10 @@ CODE_SAMPLE
|
||||
// when already asssigned to true
|
||||
$isRemoved = $this->complexNodeRemover->removePropertyAndUsages($node, $property, $this->removeAssignSideEffect, $scope);
|
||||
if ($isRemoved) {
|
||||
$this->processRemoveSameLineComment($node, $property, $key);
|
||||
$hasRemoved = \true;
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
return $hasRemoved ? $node : null;
|
||||
}
|
||||
private function processRemoveSameLineComment(Class_ $class, Property $property, int $key) : void
|
||||
{
|
||||
if (!isset($class->stmts[$key + 1])) {
|
||||
return;
|
||||
}
|
||||
if (!$class->stmts[$key + 1] instanceof Nop) {
|
||||
return;
|
||||
}
|
||||
if ($class->stmts[$key + 1]->getEndLine() !== $property->getStartLine()) {
|
||||
return;
|
||||
}
|
||||
unset($class->stmts[$key + 1]);
|
||||
return $hasChanged ? $node : null;
|
||||
}
|
||||
private function shouldSkipProperty(Property $property) : bool
|
||||
{
|
||||
|
@ -98,28 +98,33 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Property::class, ClassMethod::class];
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Property|ClassMethod $node
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node instanceof ClassMethod) {
|
||||
$hasChanged = \false;
|
||||
foreach ($node->params as $param) {
|
||||
$justChanged = $this->refactorParam($node, $param, $scope);
|
||||
// different variable to ensure $hasChanged not replaced
|
||||
$hasChanged = \false;
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
foreach ($classMethod->params as $param) {
|
||||
$justChanged = $this->refactorParam($node, $classMethod, $param, $scope);
|
||||
// different variable to ensure $hasRemoved not replaced
|
||||
if ($justChanged instanceof Param) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return $this->refactorProperty($node, $scope);
|
||||
foreach ($node->getProperties() as $property) {
|
||||
$changedProperty = $this->refactorProperty($node, $property, $scope);
|
||||
if ($changedProperty instanceof Property) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if ($hasChanged) {
|
||||
return $node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
@ -136,7 +141,7 @@ CODE_SAMPLE
|
||||
}
|
||||
return $class->isReadonly();
|
||||
}
|
||||
private function refactorProperty(Property $property, Scope $scope) : ?Property
|
||||
private function refactorProperty(Class_ $class, Property $property, Scope $scope) : ?Property
|
||||
{
|
||||
// 1. is property read-only?
|
||||
if ($property->isReadonly()) {
|
||||
@ -154,7 +159,7 @@ CODE_SAMPLE
|
||||
if (!$this->visibilityManipulator->hasVisibility($property, Visibility::PRIVATE)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($property, $scope)) {
|
||||
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($class, $property, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->propertyFetchAssignManipulator->isAssignedMultipleTimesInConstructor($property)) {
|
||||
@ -170,7 +175,7 @@ CODE_SAMPLE
|
||||
}
|
||||
return $property;
|
||||
}
|
||||
private function refactorParam(ClassMethod $classMethod, Param $param, Scope $scope) : ?\PhpParser\Node\Param
|
||||
private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $param, Scope $scope) : ?\PhpParser\Node\Param
|
||||
{
|
||||
if (!$this->visibilityManipulator->hasVisibility($param, Visibility::PRIVATE)) {
|
||||
return null;
|
||||
@ -179,7 +184,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
// promoted property?
|
||||
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($param, $scope)) {
|
||||
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($class, $param, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->visibilityManipulator->isReadonly($param)) {
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '953ecb9ecd02d5fc13a21cd7086b60aa45eac31d';
|
||||
public const PACKAGE_VERSION = '22e97d1c418d0772cf449ed888522ca060829ddf';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-30 12:34:47';
|
||||
public const RELEASE_DATE = '2023-05-30 14:01:00';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -185,18 +185,10 @@ final class PropertyManipulator
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $propertyOrParam
|
||||
*/
|
||||
public function isPropertyChangeableExceptConstructor($propertyOrParam, Scope $scope) : bool
|
||||
public function isPropertyChangeableExceptConstructor(Class_ $class, $propertyOrParam, Scope $scope) : bool
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($propertyOrParam, Class_::class);
|
||||
// does not have parent type ClassLike? Possibly parent is changed by other rule
|
||||
if (!$class instanceof Class_) {
|
||||
return \true;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
|
||||
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->phpAttributeAnalyzer->hasPhpAttributes($class, self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
|
||||
if ($this->hasAllowedNotReadonlyAnnotationOrAttribute($phpDocInfo, $class)) {
|
||||
return \true;
|
||||
}
|
||||
$propertyFetches = $this->propertyFetchFinder->findPrivatePropertyFetches($class, $propertyOrParam);
|
||||
@ -333,4 +325,11 @@ final class PropertyManipulator
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function hasAllowedNotReadonlyAnnotationOrAttribute(PhpDocInfo $phpDocInfo, Class_ $class) : bool
|
||||
{
|
||||
if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) {
|
||||
return \true;
|
||||
}
|
||||
return $this->phpAttributeAnalyzer->hasPhpAttributes($class, self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
|
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 ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1::getLoader();
|
||||
return ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1::getLoader();
|
||||
|
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 ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1
|
||||
class ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit18ca20d17b299a5129994679ad8528a1::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1
|
||||
class ComposerStaticInit18ca20d17b299a5129994679ad8528a1
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3085,9 +3085,9 @@ class ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user