Skip to content

Commit

Permalink
Updated Rector to commit 1aef75583cc0c1314f151c24fac27e7af69e7d7d
Browse files Browse the repository at this point in the history
rectorphp/rector-src@1aef755 [TypeDeclaration] Clean up get ClassReflection on loop on TypedPropertyFromCreateMockAssignRector (#6181)
  • Loading branch information
TomasVotruba committed Jul 24, 2024
1 parent b7033ef commit 19fc78b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
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;
Expand All @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -101,7 +93,6 @@ public function refactor(Node $node) : ?Node
if (!$this->isObjectType($node, new ObjectType(self::TEST_CASE_CLASS))) {
return null;
}
$classReflection = null;
$hasChanged = \false;
foreach ($node->getProperties() as $property) {
// already typed
Expand All @@ -111,14 +102,8 @@ public function refactor(Node $node) : ?Node
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;
}
Expand All @@ -129,7 +114,6 @@ public function refactor(Node $node) : ?Node
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 19fc78b

Please sign in to comment.