Updated Rector to commit 0a7be603fcc467ac3956081bf83db9c0d5350eee

0a7be603fc Remove MakeTypedPropertyNullableIfCheckedRector as old fix of TypedPropertyRector rule, removed months ago (#3851)
This commit is contained in:
Tomas Votruba 2023-05-14 16:14:48 +00:00
parent a8cb615a7e
commit 270692ae54
8 changed files with 14 additions and 261 deletions

View File

@ -84,7 +84,6 @@ use Rector\Config\RectorConfig;
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
@ -112,5 +111,5 @@ return static function (RectorConfig $rectorConfig) : void {
'mbstrrpos' => 'mb_strrpos',
'mbsubstr' => 'mb_substr',
]);
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SimplifyForeachToArrayFilterRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, RemoveAlwaysTrueConditionSetInConstructorRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, AddPregQuoteDelimiterRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, ArrayKeysAndInArrayToArrayKeyExistsRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, ExplicitMethodCallOverMagicGetSetRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, MakeTypedPropertyNullableIfCheckedRector::class, DisallowedEmptyRuleFixerRector::class]);
$rectorConfig->rules([CombinedAssignRector::class, SimplifyEmptyArrayCheckRector::class, ReplaceMultipleBooleanNotRector::class, ForeachToInArrayRector::class, SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, SimplifyStrposLowerRector::class, GetClassToInstanceOfRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class, SimplifyIfReturnBoolRector::class, SimplifyUselessVariableRector::class, UnnecessaryTernaryExpressionRector::class, RemoveExtraParametersRector::class, SimplifyDeMorganBinaryRector::class, SimplifyTautologyTernaryRector::class, SimplifyForeachToArrayFilterRector::class, SingleInArrayToCompareRector::class, SimplifyIfElseToTernaryRector::class, JoinStringConcatRector::class, ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, ExplicitBoolCompareRector::class, CombineIfRector::class, UseIdenticalOverEqualWithSameTypeRector::class, SimplifyBoolIdenticalTrueRector::class, SimplifyRegexPatternRector::class, BooleanNotIdenticalToNotIdenticalRector::class, StrvalToTypeCastRector::class, FloatvalToTypeCastRector::class, CallableThisArrayToAnonymousFunctionRector::class, AndAssignsToSeparateLinesRector::class, CompactToVariablesRector::class, CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, RemoveAlwaysTrueConditionSetInConstructorRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ShortenElseIfRector::class, AddPregQuoteDelimiterRector::class, ArrayMergeOfNonArraysToSimpleArrayRector::class, IntvalToTypeCastRector::class, BoolvalToTypeCastRector::class, ArrayKeyExistsTernaryThenValueToCoalescingRector::class, AbsolutizeRequireAndIncludePathRector::class, ChangeArrayPushToArrayAssignRector::class, ForRepeatedCountToOwnVariableRector::class, ForeachItemsAssignToEmptyArrayToAssignRector::class, InlineIfToExplicitIfRector::class, ArrayKeysAndInArrayToArrayKeyExistsRector::class, UnusedForeachValueToArrayKeysRector::class, CommonNotEqualRector::class, SetTypeToCastRector::class, LogicalToBooleanRector::class, VarToPublicPropertyRector::class, IssetOnPropertyObjectToPropertyExistsRector::class, NewStaticToNewSelfRector::class, UnwrapSprintfOneArgumentRector::class, SwitchNegatedTernaryRector::class, SingularSwitchToIfRector::class, SimplifyIfNullableReturnRector::class, FuncGetArgsToVariadicParamRector::class, CallUserFuncToMethodCallRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, CountArrayToEmptyArrayComparisonRector::class, FlipTypeControlToUseExclusiveTypeRector::class, ExplicitMethodCallOverMagicGetSetRector::class, InlineArrayReturnAssignRector::class, InlineIsAInstanceOfRector::class, TernaryFalseExpressionToIfRector::class, InlineConstructorDefaultToPropertyRector::class, ReturnTypeFromStrictScalarReturnExprRector::class, TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, OptionalParametersAfterRequiredRector::class, SimplifyEmptyCheckOnEmptyArrayRector::class, SwitchTrueToIfRector::class, CleanupUnneededNullsafeOperatorRector::class, DisallowedEmptyRuleFixerRector::class]);
};

View File

@ -1,4 +1,4 @@
# 408 Rules Overview
# 406 Rules Overview
<br>
@ -58,8 +58,6 @@
- [Renaming](#renaming) (11)
- [Restoration](#restoration) (2)
- [Strict](#strict) (6)
- [Transform](#transform) (30)
@ -7345,50 +7343,6 @@ return static function (RectorConfig $rectorConfig): void {
<br>
## Restoration
### MakeTypedPropertyNullableIfCheckedRector
Make typed property nullable if checked
- class: [`Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector`](../rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php)
```diff
final class SomeClass
{
- private AnotherClass $anotherClass;
+ private ?AnotherClass $anotherClass = null;
public function run()
{
if ($this->anotherClass === null) {
$this->anotherClass = new AnotherClass;
}
}
}
```
<br>
### MissingClassConstantReferenceToStringRector
Convert missing class reference to string
- class: [`Rector\Restoration\Rector\ClassConstFetch\MissingClassConstantReferenceToStringRector`](../rules/Restoration/Rector/ClassConstFetch/MissingClassConstantReferenceToStringRector.php)
```diff
class SomeClass
{
public function run()
{
- return NonExistingClass::class;
+ return 'NonExistingClass';
}
}
```
<br>
## Strict
### AddConstructorParentCallRector

View File

@ -1,198 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Restoration\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use Rector\Core\Rector\AbstractRector;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector\MakeTypedPropertyNullableIfCheckedRectorTest
*/
final class MakeTypedPropertyNullableIfCheckedRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/
private $visibilityManipulator;
/**
* @readonly
* @var \Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector
*/
private $constructorAssignDetector;
public function __construct(VisibilityManipulator $visibilityManipulator, ConstructorAssignDetector $constructorAssignDetector)
{
$this->visibilityManipulator = $visibilityManipulator;
$this->constructorAssignDetector = $constructorAssignDetector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Make typed property nullable if checked', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
private AnotherClass $anotherClass;
public function run()
{
if ($this->anotherClass === null) {
$this->anotherClass = new AnotherClass;
}
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
private ?AnotherClass $anotherClass = null;
public function run()
{
if ($this->anotherClass === null) {
$this->anotherClass = new AnotherClass;
}
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Property::class];
}
/**
* @param Property $node
*/
public function refactor(Node $node) : ?Node
{
if ($this->shouldSkipProperty($node)) {
return null;
}
/** @var PropertyProperty $onlyProperty */
$onlyProperty = $node->props[0];
//Skip properties with default values
if ($onlyProperty->default instanceof Expr) {
return null;
}
$classLike = $this->betterNodeFinder->findParentType($onlyProperty, Class_::class);
if (!$classLike instanceof Class_) {
return null;
}
$isPropertyConstructorAssigned = $this->isPropertyConstructorAssigned($classLike, $onlyProperty);
if ($isPropertyConstructorAssigned) {
return null;
}
$isPropertyNullChecked = $this->isPropertyNullChecked($classLike, $onlyProperty);
if (!$isPropertyNullChecked) {
return null;
}
if ($node->type instanceof ComplexType) {
return null;
}
$currentPropertyType = $node->type;
if ($currentPropertyType === null) {
return null;
}
$node->type = new NullableType($currentPropertyType);
$onlyProperty->default = $this->nodeFactory->createNull();
if ($node->isReadonly()) {
$this->visibilityManipulator->removeReadonly($node);
}
return $node;
}
private function shouldSkipProperty(Property $property) : bool
{
if (\count($property->props) !== 1) {
return \true;
}
if ($property->type === null) {
return \true;
}
return $property->type instanceof NullableType;
}
private function isPropertyConstructorAssigned(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
{
$propertyName = $this->nodeNameResolver->getName($onlyPropertyProperty);
return $this->constructorAssignDetector->isPropertyAssigned($class, $propertyName);
}
private function isPropertyNullChecked(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
{
if ($this->isIdenticalOrNotIdenticalToNull($class, $onlyPropertyProperty)) {
return \true;
}
return $this->isBooleanNot($class, $onlyPropertyProperty);
}
private function isIdenticalOrNotIdenticalToNull(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
{
$isIdenticalOrNotIdenticalToNull = \false;
$this->traverseNodesWithCallable($class->stmts, function (Node $node) use($onlyPropertyProperty, &$isIdenticalOrNotIdenticalToNull) {
$matchedPropertyFetchName = $this->matchPropertyFetchNameComparedToNull($node);
if ($matchedPropertyFetchName === null) {
return null;
}
if (!$this->isName($onlyPropertyProperty, $matchedPropertyFetchName)) {
return null;
}
$isIdenticalOrNotIdenticalToNull = \true;
});
return $isIdenticalOrNotIdenticalToNull;
}
private function isBooleanNot(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
{
$isBooleanNot = \false;
$this->traverseNodesWithCallable($class->stmts, function (Node $node) use($onlyPropertyProperty, &$isBooleanNot) {
if (!$node instanceof BooleanNot) {
return null;
}
if (!$node->expr instanceof PropertyFetch) {
return null;
}
if (!$this->isName($node->expr->var, 'this')) {
return null;
}
if (!$this->nodeNameResolver->areNamesEqual($onlyPropertyProperty, $node->expr->name)) {
return null;
}
$isBooleanNot = \true;
});
return $isBooleanNot;
}
/**
* Matches:
* $this-><someProprety> === null
* null === $this-><someProprety>
*/
private function matchPropertyFetchNameComparedToNull(Node $node) : ?string
{
if (!$node instanceof Identical && !$node instanceof NotIdentical) {
return null;
}
if ($node->left instanceof PropertyFetch && $this->valueResolver->isNull($node->right)) {
$propertyFetch = $node->left;
} elseif ($node->right instanceof PropertyFetch && $this->valueResolver->isNull($node->left)) {
$propertyFetch = $node->right;
} else {
return null;
}
if (!$this->isName($propertyFetch->var, 'this')) {
return null;
}
return $this->getName($propertyFetch->name);
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '7935b2a3c2371e0d9e18ad2b683ac3b53b64d950';
public const PACKAGE_VERSION = '0a7be603fcc467ac3956081bf83db9c0d5350eee';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-14 17:03:51';
public const RELEASE_DATE = '2023-05-14 16:09:49';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit77e6a482da193fd652cfd0c58417d900::getLoader();
return ComposerAutoloaderInita45dccfe8a7ea22904f9b8ba9f59e519::getLoader();

View File

@ -2445,7 +2445,6 @@ return array(
'Rector\\Renaming\\ValueObject\\RenameProperty' => $baseDir . '/rules/Renaming/ValueObject/RenameProperty.php',
'Rector\\Renaming\\ValueObject\\RenameStaticMethod' => $baseDir . '/rules/Renaming/ValueObject/RenameStaticMethod.php',
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => $baseDir . '/rules/Renaming/ValueObject/RenamedNamespace.php',
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => $baseDir . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
'Rector\\Set\\Contract\\SetListInterface' => $baseDir . '/packages/Set/Contract/SetListInterface.php',
'Rector\\Set\\ValueObject\\DowngradeLevelSetList' => $vendorDir . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeLevelSetList.php',
'Rector\\Set\\ValueObject\\DowngradeSetList' => $vendorDir . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit77e6a482da193fd652cfd0c58417d900
class ComposerAutoloaderInita45dccfe8a7ea22904f9b8ba9f59e519
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit77e6a482da193fd652cfd0c58417d900
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit77e6a482da193fd652cfd0c58417d900', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInita45dccfe8a7ea22904f9b8ba9f59e519', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit77e6a482da193fd652cfd0c58417d900', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInita45dccfe8a7ea22904f9b8ba9f59e519', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit77e6a482da193fd652cfd0c58417d900::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit77e6a482da193fd652cfd0c58417d900::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit77e6a482da193fd652cfd0c58417d900
class ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2687,7 +2687,6 @@ class ComposerStaticInit77e6a482da193fd652cfd0c58417d900
'Rector\\Renaming\\ValueObject\\RenameProperty' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenameProperty.php',
'Rector\\Renaming\\ValueObject\\RenameStaticMethod' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenameStaticMethod.php',
'Rector\\Renaming\\ValueObject\\RenamedNamespace' => __DIR__ . '/../..' . '/rules/Renaming/ValueObject/RenamedNamespace.php',
'Rector\\Restoration\\Rector\\Property\\MakeTypedPropertyNullableIfCheckedRector' => __DIR__ . '/../..' . '/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php',
'Rector\\Set\\Contract\\SetListInterface' => __DIR__ . '/../..' . '/packages/Set/Contract/SetListInterface.php',
'Rector\\Set\\ValueObject\\DowngradeLevelSetList' => __DIR__ . '/..' . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeLevelSetList.php',
'Rector\\Set\\ValueObject\\DowngradeSetList' => __DIR__ . '/..' . '/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php',
@ -3106,9 +3105,9 @@ class ComposerStaticInit77e6a482da193fd652cfd0c58417d900
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit77e6a482da193fd652cfd0c58417d900::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit77e6a482da193fd652cfd0c58417d900::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit77e6a482da193fd652cfd0c58417d900::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita45dccfe8a7ea22904f9b8ba9f59e519::$classMap;
}, null, ClassLoader::class);
}