mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
Updated Rector to commit f9b3312035a4e5baee7105b19715d057587e1f59
f9b3312035
[TypeDeclaration] Include MockObject&ClassName docblock with IntersectionTypeNode on TypedPropertyFromStrictSetUpRector (#5655)
This commit is contained in:
parent
e8568e6d97
commit
adbf03fcec
|
@ -3,9 +3,15 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\TypeDeclaration\Rector\Property;
|
namespace Rector\TypeDeclaration\Rector\Property;
|
||||||
|
|
||||||
|
use PHPStan\Type\ObjectType;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
use PhpParser\Node\Stmt\Class_;
|
||||||
use PhpParser\Node\Stmt\ClassMethod;
|
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\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||||
use Rector\Rector\AbstractRector;
|
use Rector\Rector\AbstractRector;
|
||||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||||
|
@ -30,10 +36,22 @@ final class TypedPropertyFromStrictSetUpRector extends AbstractRector implements
|
||||||
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||||
*/
|
*/
|
||||||
private $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->trustedClassMethodPropertyTypeInferer = $trustedClassMethodPropertyTypeInferer;
|
||||||
$this->staticTypeMapper = $staticTypeMapper;
|
$this->staticTypeMapper = $staticTypeMapper;
|
||||||
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||||
|
$this->docBlockUpdater = $docBlockUpdater;
|
||||||
}
|
}
|
||||||
public function getRuleDefinition() : RuleDefinition
|
public function getRuleDefinition() : RuleDefinition
|
||||||
{
|
{
|
||||||
|
@ -96,6 +114,15 @@ CODE_SAMPLE
|
||||||
if (!$propertyTypeNode instanceof Node) {
|
if (!$propertyTypeNode instanceof Node) {
|
||||||
continue;
|
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;
|
$property->type = $propertyTypeNode;
|
||||||
$hasChanged = \true;
|
$hasChanged = \true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '8038ee15844b7753e5698bd42b62669d9ebca12b';
|
public const PACKAGE_VERSION = 'f9b3312035a4e5baee7105b19715d057587e1f59';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2024-02-22 03:25:47';
|
public const RELEASE_DATE = '2024-02-22 15:43:48';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user