Skip to content

Commit 9cab1db

Browse files
committed
add same support to AddReturnDocblockForCommonObjectDenominatorRector
1 parent d5d631c commit 9cab1db

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\FirstExtension;
6+
use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\SecondExtension;
7+
8+
final class OverrideDummyArray
9+
{
10+
/**
11+
* @return array
12+
*/
13+
public function getExtensions(): array
14+
{
15+
return [
16+
new FirstExtension(),
17+
new SecondExtension()
18+
];
19+
}
20+
}
21+
22+
?>
23+
-----
24+
<?php
25+
26+
namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Fixture;
27+
28+
use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\FirstExtension;
29+
use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\SecondExtension;
30+
31+
final class OverrideDummyArray
32+
{
33+
/**
34+
* @return \Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\Contract\ExtensionInterface[]
35+
*/
36+
public function getExtensions(): array
37+
{
38+
return [
39+
new FirstExtension(),
40+
new SecondExtension()
41+
];
42+
}
43+
}
44+
45+
?>

rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function refactor(Node $node): ?Node
110110
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
111111
$returnType = $phpDocInfo->getReturnType();
112112

113-
if (! $returnType instanceof MixedType || $returnType->isExplicitMixed()) {
113+
if ($returnType instanceof ArrayType && ! $returnType->getItemType() instanceof MixedType) {
114114
return null;
115115
}
116116

@@ -175,6 +175,7 @@ public function refactor(Node $node): ?Node
175175
$this->resolveKeyType($returnedType),
176176
new FullyQualifiedObjectType($firstSharedType)
177177
);
178+
178179
$hasChanged = $this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, $objectTypeArrayType);
179180
if (! $hasChanged) {
180181
return null;

0 commit comments

Comments
 (0)