Skip to content

Commit

Permalink
Updated Rector to commit eba615375fc6b795827e4ef3135d88c58479719d
Browse files Browse the repository at this point in the history
rectorphp/rector-src@eba6153 [TypeDeclaration] Allow defined in non-setUp() on TypedPropertyFromCreateMockAssignRector (#6180)
  • Loading branch information
TomasVotruba committed Jul 23, 2024
1 parent ceea11f commit 90fab4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
namespace Rector\TypeDeclaration\Rector\Class_;

use PhpParser\Node;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
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\ValueObject\MethodName;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -39,6 +39,11 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
/**
* @readonly
* @var \Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector
*/
private $constructorAssignDetector;
/**
* @var string
*/
Expand All @@ -47,11 +52,12 @@ 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)
public function __construct(ReflectionResolver $reflectionResolver, AllAssignNodePropertyTypeInferer $allAssignNodePropertyTypeInferer, StaticTypeMapper $staticTypeMapper, ConstructorAssignDetector $constructorAssignDetector)
{
$this->reflectionResolver = $reflectionResolver;
$this->allAssignNodePropertyTypeInferer = $allAssignNodePropertyTypeInferer;
$this->staticTypeMapper = $staticTypeMapper;
$this->constructorAssignDetector = $constructorAssignDetector;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -102,8 +108,7 @@ public function refactor(Node $node) : ?Node
if ($property->type instanceof Node) {
continue;
}
$setUpClassMethod = $node->getMethod(MethodName::SET_UP);
if (!$setUpClassMethod instanceof ClassMethod) {
if (\count($property->props) !== 1) {
continue;
}
if (!$classReflection instanceof ClassReflection) {
Expand All @@ -124,6 +129,13 @@ 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;
}
$property->props[0]->default = $this->nodeFactory->createNull();
}
$property->type = $propertyType;
$hasChanged = \true;
}
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 = '1a58300b7d6ccaa1adbb1760b4a355263dc41408';
public const PACKAGE_VERSION = 'eba615375fc6b795827e4ef3135d88c58479719d';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-24 04:50:32';
public const RELEASE_DATE = '2024-07-24 06:00:39';
/**
* @var int
*/
Expand Down

0 comments on commit 90fab4d

Please sign in to comment.