Updated Rector to commit b5ddb028c0b29c03b20fb4967f88873ddfd42411

b5ddb028c0 Skip MakeTypedPropertyNullableIfCheckedRector for constructor assigment. (#3074)
This commit is contained in:
Tomas Votruba 2022-11-18 00:08:55 +00:00
parent d085266247
commit dcc7f6941e
5 changed files with 39 additions and 23 deletions

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\Stmt\PropertyProperty;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractRector;
use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** /**
@ -28,9 +29,15 @@ final class MakeTypedPropertyNullableIfCheckedRector extends AbstractRector
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator * @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/ */
private $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->visibilityManipulator = $visibilityManipulator;
$this->constructorAssignDetector = $constructorAssignDetector;
} }
public function getRuleDefinition() : RuleDefinition public function getRuleDefinition() : RuleDefinition
{ {
@ -83,7 +90,15 @@ CODE_SAMPLE
if ($onlyProperty->default instanceof Expr) { if ($onlyProperty->default instanceof Expr) {
return null; 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) { if (!$isPropertyNullChecked) {
return null; return null;
} }
@ -111,16 +126,17 @@ CODE_SAMPLE
} }
return $property->type instanceof NullableType; 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); $propertyName = $this->nodeNameResolver->getName($onlyPropertyProperty);
if (!$classLike instanceof Class_) { return $this->constructorAssignDetector->isPropertyAssigned($class, $propertyName);
return \false; }
} private function isPropertyNullChecked(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
if ($this->isIdenticalOrNotIdenticalToNull($classLike, $onlyPropertyProperty)) { {
if ($this->isIdenticalOrNotIdenticalToNull($class, $onlyPropertyProperty)) {
return \true; return \true;
} }
return $this->isBooleanNot($classLike, $onlyPropertyProperty); return $this->isBooleanNot($class, $onlyPropertyProperty);
} }
private function isIdenticalOrNotIdenticalToNull(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool private function isIdenticalOrNotIdenticalToNull(Class_ $class, PropertyProperty $onlyPropertyProperty) : bool
{ {

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = 'a1df08d2dfe392f42b58288c47646e2a565851dc'; public const PACKAGE_VERSION = 'b5ddb028c0b29c03b20fb4967f88873ddfd42411';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2022-11-17 17:51:22'; public const RELEASE_DATE = '2022-11-18 01:04:25';
/** /**
* @var int * @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'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485::getLoader(); return ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485 class ComposerAutoloaderInit65c2a16b3414aa69dba3c9441083942b
{ {
private static $loader; private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485
return self::$loader; 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__)); 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'; 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->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$files; $includeFiles = \Composer\Autoload\ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$files;
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire1b20863ba1f8727b7dfa4f32e6fd5485($fileIdentifier, $file); composerRequire65c2a16b3414aa69dba3c9441083942b($fileIdentifier, $file);
} }
return $loader; return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit1b20863ba1f8727b7dfa4f32e6fd5485
* @param string $file * @param string $file
* @return void * @return void
*/ */
function composerRequire1b20863ba1f8727b7dfa4f32e6fd5485($fileIdentifier, $file) function composerRequire65c2a16b3414aa69dba3c9441083942b($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485 class ComposerStaticInit65c2a16b3414aa69dba3c9441083942b
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3036,9 +3036,9 @@ class ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1b20863ba1f8727b7dfa4f32e6fd5485::$classMap; $loader->classMap = ComposerStaticInit65c2a16b3414aa69dba3c9441083942b::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }