|
20 | 20 | use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; |
21 | 21 | use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; |
22 | 22 | use Rector\Rector\AbstractRector; |
| 23 | +use Rector\TypeDeclaration\NodeAnalyzer\NeverFuncCallAnalyzer; |
23 | 24 | use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; |
24 | 25 | use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver; |
25 | 26 | use Rector\ValueObject\MethodName; |
@@ -50,17 +51,23 @@ final class ExplicitReturnNullRector extends AbstractRector |
50 | 51 | * @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger |
51 | 52 | */ |
52 | 53 | private $phpDocTypeChanger; |
| 54 | + /** |
| 55 | + * @readonly |
| 56 | + * @var \Rector\TypeDeclaration\NodeAnalyzer\NeverFuncCallAnalyzer |
| 57 | + */ |
| 58 | + private $neverFuncCallAnalyzer; |
53 | 59 | /** |
54 | 60 | * @readonly |
55 | 61 | * @var \Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer |
56 | 62 | */ |
57 | 63 | private $returnTypeInferer; |
58 | | - public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer) |
| 64 | + public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, NeverFuncCallAnalyzer $neverFuncCallAnalyzer, ReturnTypeInferer $returnTypeInferer) |
59 | 65 | { |
60 | 66 | $this->silentVoidResolver = $silentVoidResolver; |
61 | 67 | $this->phpDocInfoFactory = $phpDocInfoFactory; |
62 | 68 | $this->typeFactory = $typeFactory; |
63 | 69 | $this->phpDocTypeChanger = $phpDocTypeChanger; |
| 70 | + $this->neverFuncCallAnalyzer = $neverFuncCallAnalyzer; |
64 | 71 | $this->returnTypeInferer = $returnTypeInferer; |
65 | 72 | } |
66 | 73 | public function getRuleDefinition() : RuleDefinition |
@@ -132,7 +139,7 @@ public function refactor(Node $node) : ?Node |
132 | 139 | } |
133 | 140 | return null; |
134 | 141 | }); |
135 | | - if (!$this->silentVoidResolver->hasSilentVoid($node)) { |
| 142 | + if (!$this->silentVoidResolver->hasSilentVoid($node) || $this->neverFuncCallAnalyzer->hasNeverFuncCall($node)) { |
136 | 143 | if ($hasChanged) { |
137 | 144 | $this->transformDocUnionVoidToUnionNull($node); |
138 | 145 | return $node; |
|
0 commit comments