Skip to content

Commit e8f5971

Browse files
committed
Updated Rector to commit 4904b4d7e9233eb9ac089a42de6020804fcb39e1
rectorphp/rector-src@4904b4d [type-declaration] Skip intersection type on TypedPropertyFromCreateMockAssignRector (#6863)
1 parent d2f553f commit e8f5971

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

rules/TypeDeclaration/Rector/Class_/TypedPropertyFromCreateMockAssignRector.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
namespace Rector\TypeDeclaration\Rector\Class_;
55

66
use PhpParser\Node;
7+
use PhpParser\Node\IntersectionType;
78
use PhpParser\Node\NullableType;
89
use PhpParser\Node\Stmt\Class_;
10+
use PhpParser\Node\Stmt\Property;
911
use PHPStan\Type\ObjectType;
1012
use PHPStan\Type\Type;
1113
use Rector\Enum\ClassName;
@@ -43,7 +45,7 @@ public function __construct(AssignToPropertyTypeInferer $assignToPropertyTypeInf
4345
}
4446
public function getRuleDefinition() : RuleDefinition
4547
{
46-
return new RuleDefinition('Add typed property from assigned mock', [new CodeSample(<<<'CODE_SAMPLE'
48+
return new RuleDefinition('Add "PHPUnit\\Framework\\MockObject\\MockObject" typed property from assigned mock to clearly separate from real objects', [new CodeSample(<<<'CODE_SAMPLE'
4749
use PHPUnit\Framework\TestCase;
4850
4951
final class SomeTest extends TestCase
@@ -58,10 +60,11 @@ protected function setUp(): void
5860
CODE_SAMPLE
5961
, <<<'CODE_SAMPLE'
6062
use PHPUnit\Framework\TestCase;
63+
use PHPUnit\Framework\MockObject\MockObject;
6164
6265
final class SomeTest extends TestCase
6366
{
64-
private \PHPUnit\Framework\MockObject\MockObject $someProperty;
67+
private MockObject $someProperty;
6568
6669
protected function setUp(): void
6770
{
@@ -85,11 +88,11 @@ public function refactor(Node $node) : ?Node
8588
}
8689
$hasChanged = \false;
8790
foreach ($node->getProperties() as $property) {
88-
// already use PHPUnit\Framework\MockObject\MockObject type
89-
if ($property->type instanceof Node && $this->isObjectType($property->type, new ObjectType(ClassName::MOCK_OBJECT))) {
91+
if (\count($property->props) !== 1) {
9092
continue;
9193
}
92-
if (\count($property->props) !== 1) {
94+
// already use PHPUnit\Framework\MockObject\MockObject type
95+
if ($this->isAlreadyTypedWithMockObject($property)) {
9396
continue;
9497
}
9598
$propertyName = (string) $this->getName($property);
@@ -122,4 +125,15 @@ public function provideMinPhpVersion() : int
122125
{
123126
return PhpVersionFeature::TYPED_PROPERTIES;
124127
}
128+
private function isAlreadyTypedWithMockObject(Property $property) : bool
129+
{
130+
if (!$property->type instanceof Node) {
131+
return \false;
132+
}
133+
// complex type, used on purpose
134+
if ($property->type instanceof IntersectionType) {
135+
return \true;
136+
}
137+
return $this->isObjectType($property->type, new ObjectType(ClassName::MOCK_OBJECT));
138+
}
125139
}

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 = 'ba8614a8d2f09f3baf3c7ef930c0e26eb68e30d0';
22+
public const PACKAGE_VERSION = '4904b4d7e9233eb9ac089a42de6020804fcb39e1';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-04-24 16:04:29';
27+
public const RELEASE_DATE = '2025-04-24 21:06:39';
2828
/**
2929
* @var int
3030
*/

vendor/composer/installed.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@
512512
},
513513
{
514514
"name": "illuminate\/container",
515-
"version": "v11.44.4",
516-
"version_normalized": "11.44.4.0",
515+
"version": "v11.44.5",
516+
"version_normalized": "11.44.5.0",
517517
"source": {
518518
"type": "git",
519519
"url": "https:\/\/github.com\/illuminate\/container.git",
@@ -569,8 +569,8 @@
569569
},
570570
{
571571
"name": "illuminate\/contracts",
572-
"version": "v11.44.4",
573-
"version_normalized": "11.44.4.0",
572+
"version": "v11.44.5",
573+
"version_normalized": "11.44.5.0",
574574
"source": {
575575
"type": "git",
576576
"url": "https:\/\/github.com\/illuminate\/contracts.git",

0 commit comments

Comments
 (0)