|
18 | 18 | use Rector\TypeDeclarationDocblocks\NodeFinder\ReturnNodeFinder; |
19 | 19 | use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer; |
20 | 20 | use Rector\TypeDeclarationDocblocks\TypeResolver\ConstantArrayTypeGeneralizer; |
| 21 | +use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; |
21 | 22 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
22 | 23 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
23 | 24 | /** |
@@ -45,13 +46,18 @@ final class DocblockReturnArrayFromDirectArrayInstanceRector extends AbstractRec |
45 | 46 | * @readonly |
46 | 47 | */ |
47 | 48 | private UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer; |
48 | | - public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpDocTypeChanger $phpDocTypeChanger, ConstantArrayTypeGeneralizer $constantArrayTypeGeneralizer, ReturnNodeFinder $returnNodeFinder, UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer) |
| 49 | + /** |
| 50 | + * @readonly |
| 51 | + */ |
| 52 | + private ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard; |
| 53 | + public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpDocTypeChanger $phpDocTypeChanger, ConstantArrayTypeGeneralizer $constantArrayTypeGeneralizer, ReturnNodeFinder $returnNodeFinder, UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer, ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard) |
49 | 54 | { |
50 | 55 | $this->phpDocInfoFactory = $phpDocInfoFactory; |
51 | 56 | $this->phpDocTypeChanger = $phpDocTypeChanger; |
52 | 57 | $this->constantArrayTypeGeneralizer = $constantArrayTypeGeneralizer; |
53 | 58 | $this->returnNodeFinder = $returnNodeFinder; |
54 | 59 | $this->usefulArrayTagNodeAnalyzer = $usefulArrayTagNodeAnalyzer; |
| 60 | + $this->parentClassMethodTypeOverrideGuard = $parentClassMethodTypeOverrideGuard; |
55 | 61 | } |
56 | 62 | public function getNodeTypes(): array |
57 | 63 | { |
@@ -94,6 +100,10 @@ public function refactor(Node $node): ?Node |
94 | 100 | if ($node->stmts === null) { |
95 | 101 | return null; |
96 | 102 | } |
| 103 | + // skip overridden methods to not conflict with parent/interface @return docblock |
| 104 | + if ($node instanceof ClassMethod && $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($node)) { |
| 105 | + return null; |
| 106 | + } |
97 | 107 | $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); |
98 | 108 | if ($this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag($phpDocInfo->getReturnTagValue())) { |
99 | 109 | return null; |
|
0 commit comments