diff --git a/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php b/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php index 7867a1a2bee..eb4cdb007f8 100644 --- a/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php +++ b/rules/Restoration/Rector/Property/MakeTypedPropertyNullableIfCheckedRector.php @@ -16,6 +16,7 @@ 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; /** @@ -28,9 +29,15 @@ final class MakeTypedPropertyNullableIfCheckedRector extends AbstractRector * @var \Rector\Privatization\NodeManipulator\VisibilityManipulator */ private $visibilityManipulator; - public function __construct(VisibilityManipulator $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 { @@ -83,7 +90,15 @@ CODE_SAMPLE if ($onlyProperty->default instanceof Expr) { return null; } - $isPropertyNullChecked = $this->isPropertyNullChecked($onlyProperty); + $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; } @@ -111,16 +126,17 @@ CODE_SAMPLE } return $property->type instanceof NullableType; } - private function isPropertyNullChecked(PropertyProperty $onlyPropertyProperty) : bool + private function isPropertyConstructorAssigned(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool { - $classLike = $this->betterNodeFinder->findParentType($onlyPropertyProperty, Class_::class); - if (!$classLike instanceof Class_) { - return \false; - } - if ($this->isIdenticalOrNotIdenticalToNull($classLike, $onlyPropertyProperty)) { + $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($classLike, $onlyPropertyProperty); + return $this->isBooleanNot($class, $onlyPropertyProperty); } private function isIdenticalOrNotIdenticalToNull(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 45e059f060f..0ba26098c72 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -17,12 +17,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'a1df08d2dfe392f42b58288c47646e2a565851dc'; + public const PACKAGE_VERSION = 'b5ddb028c0b29c03b20fb4967f88873ddfd42411'; /** * @api * @var string */ - public const RELEASE_DATE = '2022-11-17 17:51:22'; + public const RELEASE_DATE = '2022-11-18 01:04:25'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 7785b548f9d..d381579de47 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485::getLoader(); +return ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 044d7547c9e..63b5cd626dd 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485 +class ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire1b20863ba1f8727b7dfa4f32e6fd5485($fileIdentifier, $file); + composerRequire65c2a16b3414aa69dba3c9441083942b($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485 * @param string $file * @return void */ -function composerRequire1b20863ba1f8727b7dfa4f32e6fd5485($fileIdentifier, $file) +function composerRequire65c2a16b3414aa69dba3c9441083942b($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 15e17658626..f4d2319d84e 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485 +class ComposerStaticInit65c2a16b3414aa69dba3c9441083942b { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3036,9 +3036,9 @@ class ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$classMap; }, null, ClassLoader::class); }