Skip to content

Commit

Permalink
Updated Rector to commit 07fffd50f3b62196856f22622815768385554272
Browse files Browse the repository at this point in the history
rectorphp/rector-src@07fffd5 [TypeDeclaration] Skip possible value resetted on TypedPropertyFromCreateMockAssignRector (#6178)
  • Loading branch information
TomasVotruba committed Jul 23, 2024
1 parent 8d7c7fa commit 65dfd8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
namespace Rector\TypeDeclaration\Rector\Class_;

use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\NeverType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\NodeManipulator\ClassMethodPropertyFetchManipulator;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\TrustedClassMethodPropertyTypeInferer;
use Rector\ValueObject\MethodName;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand All @@ -26,9 +24,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
{
/**
* @readonly
* @var \Rector\NodeManipulator\ClassMethodPropertyFetchManipulator
* @var \Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\TrustedClassMethodPropertyTypeInferer
*/
private $classMethodPropertyFetchManipulator;
private $trustedClassMethodPropertyTypeInferer;
/**
* @var string
*/
Expand All @@ -37,9 +35,9 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
* @var string
*/
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
public function __construct(ClassMethodPropertyFetchManipulator $classMethodPropertyFetchManipulator)
public function __construct(TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer)
{
$this->classMethodPropertyFetchManipulator = $classMethodPropertyFetchManipulator;
$this->trustedClassMethodPropertyTypeInferer = $trustedClassMethodPropertyTypeInferer;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -89,16 +87,12 @@ public function refactor(Node $node) : ?Node
if ($property->type instanceof Node) {
continue;
}
$propertyName = $this->getName($property);
$setUpClassMethod = $node->getMethod(MethodName::SET_UP);
if (!$setUpClassMethod instanceof ClassMethod) {
continue;
}
$assignedType = $this->resolveSingleAssignedExprType($setUpClassMethod, $propertyName);
if (!$assignedType instanceof Type) {
continue;
}
if (!$this->isMockObjectType($assignedType)) {
$type = $this->trustedClassMethodPropertyTypeInferer->inferProperty($node, $property, $setUpClassMethod);
if (!$this->isMockObjectType($type)) {
continue;
}
$property->type = new FullyQualified(self::MOCK_OBJECT_CLASS);
Expand Down Expand Up @@ -130,18 +124,4 @@ private function isIntersectionWithMockObjectType(Type $type) : bool
}
return \in_array(self::MOCK_OBJECT_CLASS, $type->getObjectClassNames());
}
private function resolveSingleAssignedExprType(ClassMethod $setUpClassMethod, string $propertyName) : ?Type
{
$assignedExprs = $this->classMethodPropertyFetchManipulator->findAssignsToPropertyName($setUpClassMethod, $propertyName);
if (\count($assignedExprs) !== 1) {
return null;
}
$assignedExpr = $assignedExprs[0];
$exprType = $this->getType($assignedExpr);
// work around finalized class mock
if ($exprType instanceof NeverType && $assignedExpr instanceof MethodCall && $this->isName($assignedExpr->name, 'createMock')) {
return new ObjectType(self::MOCK_OBJECT_CLASS);
}
return $exprType;
}
}
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 = '417b208b58da94040e01c5f9629ae33db472df78';
public const PACKAGE_VERSION = '07fffd50f3b62196856f22622815768385554272';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-23 19:09:34';
public const RELEASE_DATE = '2024-07-24 04:19:19';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/scoper-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Restore the backup and ensure the excluded files are properly marked as loaded
$GLOBALS['__composer_autoload_files'] = \array_merge(
$existingComposerAutoloadFiles,
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
);

return $loader;
Expand Down

0 comments on commit 65dfd8c

Please sign in to comment.