Updated Rector to commit 56c84ba714b135a36e7e95fdf53f406b1411461e

56c84ba714 [TypeDeclaration] Do not add default value when assigned in __construct() on TypedPropertyFromStrictGetterMethodReturnTypeRector (#4886)
This commit is contained in:
Tomas Votruba 2023-08-31 11:38:41 +00:00
parent a3ea8375c9
commit 62fe44207e
5 changed files with 28 additions and 17 deletions

View File

@ -3,9 +3,9 @@
declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\Property;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\MixedType;
@ -19,6 +19,7 @@ use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\Privatization\Guard\ParentPropertyLookupGuard;
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\GetterTypeDeclarationPropertyTypeInferer;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -48,12 +49,18 @@ final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends Abstract
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(GetterTypeDeclarationPropertyTypeInferer $getterTypeDeclarationPropertyTypeInferer, VarTagRemover $varTagRemover, ParentPropertyLookupGuard $parentPropertyLookupGuard, ReflectionResolver $reflectionResolver)
/**
* @readonly
* @var \Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector
*/
private $constructorAssignDetector;
public function __construct(GetterTypeDeclarationPropertyTypeInferer $getterTypeDeclarationPropertyTypeInferer, VarTagRemover $varTagRemover, ParentPropertyLookupGuard $parentPropertyLookupGuard, ReflectionResolver $reflectionResolver, ConstructorAssignDetector $constructorAssignDetector)
{
$this->getterTypeDeclarationPropertyTypeInferer = $getterTypeDeclarationPropertyTypeInferer;
$this->varTagRemover = $varTagRemover;
$this->parentPropertyLookupGuard = $parentPropertyLookupGuard;
$this->reflectionResolver = $reflectionResolver;
$this->constructorAssignDetector = $constructorAssignDetector;
}
public function getRuleDefinition() : RuleDefinition
{
@ -105,8 +112,9 @@ CODE_SAMPLE
if ($getterReturnType instanceof MixedType) {
continue;
}
$isAssignedInConstructor = $this->constructorAssignDetector->isPropertyAssigned($node, $this->getName($property));
// if property is public, it should be nullable
if ($property->isPublic() && !TypeCombinator::containsNull($getterReturnType)) {
if ($property->isPublic() && !TypeCombinator::containsNull($getterReturnType) && !$isAssignedInConstructor) {
$getterReturnType = TypeCombinator::addNull($getterReturnType);
}
$propertyTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($getterReturnType, TypeKind::PROPERTY);
@ -118,7 +126,7 @@ CODE_SAMPLE
continue;
}
$property->type = $propertyTypeNode;
$this->decorateDefaultExpr($getterReturnType, $property);
$this->decorateDefaultExpr($getterReturnType, $property, $isAssignedInConstructor);
$this->refactorPhpDoc($property);
$hasChanged = \true;
}
@ -131,8 +139,11 @@ CODE_SAMPLE
{
return PhpVersionFeature::TYPED_PROPERTIES;
}
private function decorateDefaultExpr(Type $propertyType, Property $property) : void
private function decorateDefaultExpr(Type $propertyType, Property $property, bool $isAssignedInConstructor) : void
{
if ($isAssignedInConstructor) {
return;
}
$propertyProperty = $property->props[0];
// already has a default value
if ($propertyProperty->default instanceof Expr) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '4b0a688b8117689c243adc1c8dd18e9512673428';
public const PACKAGE_VERSION = '56c84ba714b135a36e7e95fdf53f406b1411461e';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-31 17:33:27';
public const RELEASE_DATE = '2023-08-31 18:36:07';
/**
* @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 ComposerAutoloaderInitb695178ea6eb4506085e29dc276a6901::getLoader();
return ComposerAutoloaderInit8913464f6c73a0a43789c62d1488aa80::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitb695178ea6eb4506085e29dc276a6901
class ComposerAutoloaderInit8913464f6c73a0a43789c62d1488aa80
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitb695178ea6eb4506085e29dc276a6901
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitb695178ea6eb4506085e29dc276a6901', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit8913464f6c73a0a43789c62d1488aa80', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitb695178ea6eb4506085e29dc276a6901', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit8913464f6c73a0a43789c62d1488aa80', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb695178ea6eb4506085e29dc276a6901::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit8913464f6c73a0a43789c62d1488aa80::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitb695178ea6eb4506085e29dc276a6901::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit8913464f6c73a0a43789c62d1488aa80::$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 ComposerStaticInitb695178ea6eb4506085e29dc276a6901
class ComposerStaticInit8913464f6c73a0a43789c62d1488aa80
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2607,9 +2607,9 @@ class ComposerStaticInitb695178ea6eb4506085e29dc276a6901
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb695178ea6eb4506085e29dc276a6901::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb695178ea6eb4506085e29dc276a6901::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb695178ea6eb4506085e29dc276a6901::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit8913464f6c73a0a43789c62d1488aa80::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8913464f6c73a0a43789c62d1488aa80::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8913464f6c73a0a43789c62d1488aa80::$classMap;
}, null, ClassLoader::class);
}