Skip to content

Commit c8dd7ee

Browse files
committed
skip method guarded by parent interface contract
1 parent 3dc6dbd commit c8dd7ee

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

rules-tests/Php84/Rector/Class_/PropertyHookRector/Fixture/skip_parent_contract.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;
44

5-
use Php84\Rector\Class_\PropertyHookRector\Source\SomeParentContractInterface;
5+
use Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Source\SomeParentContractInterface;
66

77
final class SkipParentContract implements SomeParentContractInterface
88
{

rules-tests/Php84/Rector/Class_/PropertyHookRector/Source/SomeParentContractInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Php84\Rector\Class_\PropertyHookRector\Source;
3+
namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Source;
44

55
interface SomeParentContractInterface
66
{

rules/Php84/Rector/Class_/PropertyHookRector.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Rector\Php84\NodeFactory\PropertyHookFactory;
1313
use Rector\Rector\AbstractRector;
1414
use Rector\ValueObject\PhpVersionFeature;
15+
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
1516
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
1617
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1718
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -24,6 +25,7 @@ final class PropertyHookRector extends AbstractRector implements MinPhpVersionIn
2425
public function __construct(
2526
private readonly SetterGetterFinder $setterGetterFinder,
2627
private readonly PropertyHookFactory $propertyHookFactory,
28+
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
2729
) {
2830
}
2931

@@ -95,15 +97,24 @@ public function refactor(Node $node): ?Node
9597
}
9698

9799
foreach ($candidateClassMethods as $candidateClassMethod) {
98-
if (count((array) $candidateClassMethod->stmts) === 1) {
99-
$propertyHook = $this->propertyHookFactory->create($candidateClassMethod, $propertyName);
100-
if (! $propertyHook instanceof PropertyHook) {
101-
continue;
102-
}
103-
104-
$property->hooks[] = $propertyHook;
105-
$classMethodsToRemove[] = $candidateClassMethod;
100+
if (count((array) $candidateClassMethod->stmts) !== 1) {
101+
continue;
106102
}
103+
104+
// avoid parent contract/method override
105+
dump($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($candidateClassMethod));
106+
107+
if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($candidateClassMethod)) {
108+
continue;
109+
}
110+
111+
$propertyHook = $this->propertyHookFactory->create($candidateClassMethod, $propertyName);
112+
if (! $propertyHook instanceof PropertyHook) {
113+
continue;
114+
}
115+
116+
$property->hooks[] = $propertyHook;
117+
$classMethodsToRemove[] = $candidateClassMethod;
107118
}
108119
}
109120

rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ public function hasOnlyPropertyAssign(ClassMethod $classMethod, string $property
5858

5959
$assign = $onlyClassMethodStmt->expr;
6060

61-
// if (! $assign->expr instanceof Variable) {
62-
// return false;
63-
// }
64-
65-
// if (! $this->nodeNameResolver->isName($assign->expr, $propertyName)) {
66-
// return false;
67-
// }
68-
//
69-
// dump(33123);
70-
// die;
71-
7261
$assignVar = $assign->var;
7362
if (! $assignVar instanceof PropertyFetch) {
7463
return false;

0 commit comments

Comments
 (0)