mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-20 07:19:47 +01:00
Updated Rector to commit 3fc24e1460dcf672b75bbe7d374a9bea4a403573
3fc24e1460
[naming] Skip mock object in RenamePropertyToMatchTypeRector to keep original "mock" suffix (#6786)
This commit is contained in:
parent
32e3939288
commit
a4e557403b
@ -38,10 +38,6 @@ final class RemoveTypedPropertyNonMockDocblockRector extends AbstractRector impl
|
||||
* @readonly
|
||||
*/
|
||||
private PhpDocInfoFactory $phpDocInfoFactory;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
|
||||
public function __construct(VarTagRemover $varTagRemover, StaticTypeMapper $staticTypeMapper, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
{
|
||||
$this->varTagRemover = $varTagRemover;
|
||||
@ -97,7 +93,7 @@ CODE_SAMPLE
|
||||
if (!$property->type instanceof FullyQualified) {
|
||||
continue;
|
||||
}
|
||||
if ($this->isObjectType($property->type, new ObjectType(self::MOCK_OBJECT_CLASS))) {
|
||||
if ($this->isObjectType($property->type, new ObjectType(ClassName::MOCK_OBJECT))) {
|
||||
continue;
|
||||
}
|
||||
$propertyDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
@ -132,7 +128,7 @@ CODE_SAMPLE
|
||||
return \false;
|
||||
}
|
||||
foreach ($varTagType->getTypes() as $unionedType) {
|
||||
if ($unionedType->isSuperTypeOf(new ObjectType(self::MOCK_OBJECT_CLASS))->yes()) {
|
||||
if ($unionedType->isSuperTypeOf(new ObjectType(ClassName::MOCK_OBJECT))->yes()) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,12 @@ declare (strict_types=1);
|
||||
namespace Rector\Naming\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Enum\ClassName;
|
||||
use Rector\Naming\ExpectedNameResolver\MatchPropertyTypeExpectedNameResolver;
|
||||
use Rector\Naming\PropertyRenamer\MatchTypePropertyRenamer;
|
||||
use Rector\Naming\PropertyRenamer\PropertyPromotionRenamer;
|
||||
@ -111,6 +113,9 @@ CODE_SAMPLE
|
||||
if (!$propertyRename instanceof PropertyRename) {
|
||||
continue;
|
||||
}
|
||||
if ($this->skipMockObjectProperty($property)) {
|
||||
continue;
|
||||
}
|
||||
$renameProperty = $this->matchTypePropertyRenamer->rename($propertyRename);
|
||||
if (!$renameProperty instanceof Property) {
|
||||
continue;
|
||||
@ -118,4 +123,15 @@ CODE_SAMPLE
|
||||
$this->hasChanged = \true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Such properties can have "xMock" names that are not compatible with "MockObject" suffix
|
||||
* They should be kept and handled by another naming rule that deals with mocks
|
||||
*/
|
||||
private function skipMockObjectProperty(Property $property) : bool
|
||||
{
|
||||
if (!$property->type instanceof Name) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isName($property->type, ClassName::MOCK_OBJECT);
|
||||
}
|
||||
}
|
||||
|
@ -39,10 +39,6 @@ final class ReturnTypeFromMockObjectRector extends AbstractRector implements Min
|
||||
* @readonly
|
||||
*/
|
||||
private ReturnAnalyzer $returnAnalyzer;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, ReturnAnalyzer $returnAnalyzer)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
@ -107,7 +103,7 @@ CODE_SAMPLE
|
||||
if (!$this->isMockObjectType($returnType)) {
|
||||
return null;
|
||||
}
|
||||
$node->returnType = new FullyQualified(self::MOCK_OBJECT_CLASS);
|
||||
$node->returnType = new FullyQualified(ClassName::MOCK_OBJECT);
|
||||
return $node;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
@ -122,11 +118,11 @@ CODE_SAMPLE
|
||||
if (\count($type->getTypes()) !== 2) {
|
||||
return \false;
|
||||
}
|
||||
return \in_array(self::MOCK_OBJECT_CLASS, $type->getObjectClassNames());
|
||||
return \in_array(ClassName::MOCK_OBJECT, $type->getObjectClassNames());
|
||||
}
|
||||
private function isMockObjectType(Type $returnType) : bool
|
||||
{
|
||||
if ($returnType instanceof ObjectType && $returnType->isInstanceOf(self::MOCK_OBJECT_CLASS)->yes()) {
|
||||
if ($returnType instanceof ObjectType && $returnType->isInstanceOf(ClassName::MOCK_OBJECT)->yes()) {
|
||||
return \true;
|
||||
}
|
||||
return $this->isIntersectionWithMockObjectType($returnType);
|
||||
|
@ -35,10 +35,6 @@ final class TypedPropertyFromCreateMockAssignRector extends AbstractRector imple
|
||||
* @readonly
|
||||
*/
|
||||
private ConstructorAssignDetector $constructorAssignDetector;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const MOCK_OBJECT_CLASS = 'PHPUnit\\Framework\\MockObject\\MockObject';
|
||||
public function __construct(AssignToPropertyTypeInferer $assignToPropertyTypeInferer, StaticTypeMapper $staticTypeMapper, ConstructorAssignDetector $constructorAssignDetector)
|
||||
{
|
||||
$this->assignToPropertyTypeInferer = $assignToPropertyTypeInferer;
|
||||
@ -105,7 +101,7 @@ CODE_SAMPLE
|
||||
if (!$propertyType instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isObjectType($propertyType, new ObjectType(self::MOCK_OBJECT_CLASS))) {
|
||||
if (!$this->isObjectType($propertyType, new ObjectType(ClassName::MOCK_OBJECT))) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->constructorAssignDetector->isPropertyAssigned($node, $propertyName)) {
|
||||
|
@ -12,6 +12,7 @@ use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
|
||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||
use Rector\Enum\ClassName;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
@ -110,11 +111,11 @@ CODE_SAMPLE
|
||||
if (!$propertyTypeNode instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
if ($propertyType instanceof ObjectType && $propertyType->getClassName() === 'PHPUnit\\Framework\\MockObject\\MockObject') {
|
||||
if ($propertyType instanceof ObjectType && $propertyType->getClassName() === ClassName::MOCK_OBJECT) {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
$varTag = $phpDocInfo->getVarTagValueNode();
|
||||
$varType = $phpDocInfo->getVarType();
|
||||
if ($varTag instanceof VarTagValueNode && $varType instanceof ObjectType && $varType->getClassName() !== 'PHPUnit\\Framework\\MockObject\\MockObject') {
|
||||
if ($varTag instanceof VarTagValueNode && $varType instanceof ObjectType && $varType->getClassName() !== ClassName::MOCK_OBJECT) {
|
||||
$varTag->type = new IntersectionTypeNode([new FullyQualifiedIdentifierTypeNode($propertyType->getClassName()), new FullyQualifiedIdentifierTypeNode($varType->getClassName())]);
|
||||
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'd1e896cd58204f76a1dea43a86e8f119a8c71c9c';
|
||||
public const PACKAGE_VERSION = '3fc24e1460dcf672b75bbe7d374a9bea4a403573';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2025-03-16 00:36:29';
|
||||
public const RELEASE_DATE = '2025-03-17 12:15:54';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -9,4 +9,8 @@ final class ClassName
|
||||
* @var string
|
||||
*/
|
||||
public const TEST_CASE_CLASS = 'PHPUnit\\Framework\\TestCase';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const MOCK_OBJECT = 'PHPUnit\\Framework\\MockObject\\MockObject';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user