Skip to content

Commit 65dfd8c

Browse files
committed
Updated Rector to commit 07fffd50f3b62196856f22622815768385554272
rectorphp/rector-src@07fffd5 [TypeDeclaration] Skip possible value resetted on TypedPropertyFromCreateMockAssignRector (#6178)
1 parent 8d7c7fa commit 65dfd8c

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

rules/TypeDeclaration/Rector/Class_/TypedPropertyFromCreateMockAssignRector.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
namespace Rector\TypeDeclaration\Rector\Class_;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr\MethodCall;
87
use PhpParser\Node\Name\FullyQualified;
98
use PhpParser\Node\Stmt\Class_;
109
use PhpParser\Node\Stmt\ClassMethod;
1110
use PHPStan\Type\IntersectionType;
12-
use PHPStan\Type\NeverType;
1311
use PHPStan\Type\ObjectType;
1412
use PHPStan\Type\Type;
15-
use Rector\NodeManipulator\ClassMethodPropertyFetchManipulator;
1613
use Rector\Rector\AbstractRector;
14+
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\TrustedClassMethodPropertyTypeInferer;
1715
use Rector\ValueObject\MethodName;
1816
use Rector\ValueObject\PhpVersionFeature;
1917
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@@ -26,9 +24,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
2624
{
2725
/**
2826
* @readonly
29-
* @var \Rector\NodeManipulator\ClassMethodPropertyFetchManipulator
27+
* @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\TrustedClassMethodPropertyTypeInferer
3028
*/
31-
private $classMethodPropertyFetchManipulator;
29+
private $trustedClassMethodPropertyTypeInferer;
3230
/**
3331
* @var string
3432
*/
@@ -37,9 +35,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
3735
* @var string
3836
*/
3937
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
40-
public function __construct(ClassMethodPropertyFetchManipulator $classMethodPropertyFetchManipulator)
38+
public function __construct(TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer)
4139
{
42-
$this->classMethodPropertyFetchManipulator = $classMethodPropertyFetchManipulator;
40+
$this->trustedClassMethodPropertyTypeInferer = $trustedClassMethodPropertyTypeInferer;
4341
}
4442
public function getRuleDefinition() : RuleDefinition
4543
{
@@ -89,16 +87,12 @@ public function refactor(Node $node) : ?Node
8987
if ($property->type instanceof Node) {
9088
continue;
9189
}
92-
$propertyName = $this->getName($property);
9390
$setUpClassMethod = $node->getMethod(MethodName::SET_UP);
9491
if (!$setUpClassMethod instanceof ClassMethod) {
9592
continue;
9693
}
97-
$assignedType = $this->resolveSingleAssignedExprType($setUpClassMethod, $propertyName);
98-
if (!$assignedType instanceof Type) {
99-
continue;
100-
}
101-
if (!$this->isMockObjectType($assignedType)) {
94+
$type = $this->trustedClassMethodPropertyTypeInferer->inferProperty($node, $property, $setUpClassMethod);
95+
if (!$this->isMockObjectType($type)) {
10296
continue;
10397
}
10498
$property->type = new FullyQualified(self::MOCK_OBJECT_CLASS);
@@ -130,18 +124,4 @@ private function isIntersectionWithMockObjectType(Type $type) : bool
130124
}
131125
return \in_array(self::MOCK_OBJECT_CLASS, $type->getObjectClassNames());
132126
}
133-
private function resolveSingleAssignedExprType(ClassMethod $setUpClassMethod, string $propertyName) : ?Type
134-
{
135-
$assignedExprs = $this->classMethodPropertyFetchManipulator->findAssignsToPropertyName($setUpClassMethod, $propertyName);
136-
if (\count($assignedExprs) !== 1) {
137-
return null;
138-
}
139-
$assignedExpr = $assignedExprs[0];
140-
$exprType = $this->getType($assignedExpr);
141-
// work around finalized class mock
142-
if ($exprType instanceof NeverType && $assignedExpr instanceof MethodCall && $this->isName($assignedExpr->name, 'createMock')) {
143-
return new ObjectType(self::MOCK_OBJECT_CLASS);
144-
}
145-
return $exprType;
146-
}
147127
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '417b208b58da94040e01c5f9629ae33db472df78';
22+
public const PACKAGE_VERSION = '07fffd50f3b62196856f22622815768385554272';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-07-23 19:09:34';
27+
public const RELEASE_DATE = '2024-07-24 04:19:19';
2828
/**
2929
* @var int
3030
*/

vendor/scoper-autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Restore the backup and ensure the excluded files are properly marked as loaded
1515
$GLOBALS['__composer_autoload_files'] = \array_merge(
1616
$existingComposerAutoloadFiles,
17-
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
17+
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
1818
);
1919

2020
return $loader;

0 commit comments

Comments
 (0)