From adbf03fcec36964f59dd592a1d4049df27ff391e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 22 Feb 2024 08:46:08 +0000 Subject: [PATCH] Updated Rector to commit f9b3312035a4e5baee7105b19715d057587e1f59 https://github.com/rectorphp/rector-src/commit/f9b3312035a4e5baee7105b19715d057587e1f59 [TypeDeclaration] Include MockObject&ClassName docblock with IntersectionTypeNode on TypedPropertyFromStrictSetUpRector (#5655) --- .../TypedPropertyFromStrictSetUpRector.php | 29 ++++++++++++++++++- src/Application/VersionResolver.php | 4 +-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php index 1cef33f2765..362560be435 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php @@ -3,9 +3,15 @@ declare (strict_types=1); namespace Rector\TypeDeclaration\Rector\Property; +use PHPStan\Type\ObjectType; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; +use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode; +use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; +use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode; +use Rector\Comments\NodeDocBlock\DocBlockUpdater; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\StaticTypeMapper; @@ -30,10 +36,22 @@ final class TypedPropertyFromStrictSetUpRector extends AbstractRector implements * @var \Rector\StaticTypeMapper\StaticTypeMapper */ private $staticTypeMapper; - public function __construct(TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer, StaticTypeMapper $staticTypeMapper) + /** + * @readonly + * @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory + */ + private $phpDocInfoFactory; + /** + * @readonly + * @var \Rector\Comments\NodeDocBlock\DocBlockUpdater + */ + private $docBlockUpdater; + public function __construct(TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer, StaticTypeMapper $staticTypeMapper, PhpDocInfoFactory $phpDocInfoFactory, DocBlockUpdater $docBlockUpdater) { $this->trustedClassMethodPropertyTypeInferer = $trustedClassMethodPropertyTypeInferer; $this->staticTypeMapper = $staticTypeMapper; + $this->phpDocInfoFactory = $phpDocInfoFactory; + $this->docBlockUpdater = $docBlockUpdater; } public function getRuleDefinition() : RuleDefinition { @@ -96,6 +114,15 @@ CODE_SAMPLE if (!$propertyTypeNode instanceof Node) { continue; } + if ($propertyType instanceof ObjectType && $propertyType->getClassName() === 'PHPUnit\\Framework\\MockObject\\MockObject') { + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); + $varTag = $phpDocInfo->getVarTagValueNode(); + $varType = $phpDocInfo->getVarType(); + if ($varTag instanceof VarTagValueNode && $varType instanceof ObjectType && $varType->getClassName() !== 'PHPUnit\\Framework\\MockObject\\MockObject') { + $varTag->type = new IntersectionTypeNode([new FullyQualifiedIdentifierTypeNode($propertyType->getClassName()), new FullyQualifiedIdentifierTypeNode($varType->getClassName())]); + $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property); + } + } $property->type = $propertyTypeNode; $hasChanged = \true; } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index a174a5fcadf..477c8f23680 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '8038ee15844b7753e5698bd42b62669d9ebca12b'; + public const PACKAGE_VERSION = 'f9b3312035a4e5baee7105b19715d057587e1f59'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-02-22 03:25:47'; + public const RELEASE_DATE = '2024-02-22 15:43:48'; /** * @var int */