Updated Rector to commit 1aef75583cc0c1314f151c24fac27e7af69e7d7d

1aef75583c [TypeDeclaration] Clean up get ClassReflection on loop on TypedPropertyFromCreateMockAssignRector (#6181)
This commit is contained in:
Tomas Votruba 2024-07-24 07:51:04 +00:00
parent b7033ef12a
commit 19fc78b91d
2 changed files with 9 additions and 25 deletions

View File

@ -6,15 +6,13 @@ namespace Rector\TypeDeclaration\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer;
use Rector\TypeDeclaration\TypeInferer\AssignToPropertyTypeInferer;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -26,14 +24,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
{
/**
* @readonly
* @var \Rector\Reflection\ReflectionResolver
* @var \Rector\TypeDeclaration\TypeInferer\AssignToPropertyTypeInferer
*/
private $reflectionResolver;
/**
* @readonly
* @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer
*/
private $allAssignNodePropertyTypeInferer;
private $assignToPropertyTypeInferer;
/**
* @readonly
* @var \Rector\StaticTypeMapper\StaticTypeMapper
@ -52,10 +45,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
* @var string
*/
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
public function __construct(ReflectionResolver $reflectionResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer, StaticTypeMapper $staticTypeMapper, ConstructorAssignDetector $constructorAssignDetector)
public function __construct(AssignToPropertyTypeInferer $assignToPropertyTypeInferer, StaticTypeMapper $staticTypeMapper, ConstructorAssignDetector $constructorAssignDetector)
{
$this->reflectionResolver = $reflectionResolver;
$this->allAssignNodePropertyTypeInferer = $allAssignNodePropertyTypeInferer;
$this->assignToPropertyTypeInferer = $assignToPropertyTypeInferer;
$this->staticTypeMapper = $staticTypeMapper;
$this->constructorAssignDetector = $constructorAssignDetector;
}
@ -101,7 +93,6 @@ CODE_SAMPLE
if (!$this->isObjectType($node, new ObjectType(self::TEST_CASE_CLASS))) {
return null;
}
$classReflection = null;
$hasChanged = \false;
foreach ($node->getProperties() as $property) {
// already typed
@ -111,14 +102,8 @@ CODE_SAMPLE
if (\count($property->props) !== 1) {
continue;
}
if (!$classReflection instanceof ClassReflection) {
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
}
// ClassReflection not detected, early skip
if (!$classReflection instanceof ClassReflection) {
return null;
}
$type = $this->allAssignNodePropertyTypeInferer->inferProperty($property, $classReflection, $this->file);
$propertyName = (string) $this->getName($property);
$type = $this->assignToPropertyTypeInferer->inferPropertyInClassLike($property, $propertyName, $node);
if (!$type instanceof Type) {
continue;
}
@ -129,7 +114,6 @@ CODE_SAMPLE
if (!$this->isObjectType($propertyType, new ObjectType(self::MOCK_OBJECT_CLASS))) {
continue;
}
$propertyName = (string) $this->getName($property);
if (!$this->constructorAssignDetector->isPropertyAssigned($node, $propertyName)) {
if (!$propertyType instanceof NullableType) {
continue;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'fa84ab5de0c4b7be8125b7f6c4c60afbc2a27327';
public const PACKAGE_VERSION = '1aef75583cc0c1314f151c24fac27e7af69e7d7d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-24 08:42:51';
public const RELEASE_DATE = '2024-07-24 09:48:45';
/**
* @var int
*/