Skip to content

Commit 56f479d

Browse files
committed
[ci-review] Rector Rectify
1 parent cdb0ea6 commit 56f479d

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

rules/DeadCode/Rector/FunctionLike/NarrowTooWideReturnTypeRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rector\DeadCode\Rector\FunctionLike;
46

57
use PhpParser\Node;
@@ -24,7 +26,7 @@ public function getNodeTypes(): array
2426
return [ClassMethod::class];
2527
}
2628

27-
public function refactor(Node $node)
29+
public function refactor(Node $node): never
2830
{
2931
throw new ShouldNotHappenException(sprintf(
3032
'Class "%s" is deprecated and renamed to "%s". Use the new class instead.',

rules/TypeDeclaration/Rector/ClassMethod/NarrowObjectReturnTypeRector.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ public function getNodeTypes(): array
9595
*/
9696
public function refactor(Node $node): ?Node
9797
{
98-
if (! $node instanceof ClassMethod) {
99-
return null;
100-
}
101-
10298
$returnType = $node->returnType;
10399

104100
if (! $returnType instanceof Identifier && ! $returnType instanceof FullyQualified) {
@@ -156,7 +152,7 @@ private function isDeclaredTypeFinal(string $declaredType): bool
156152
$declaredObjectType = new ObjectType($declaredType);
157153
$classReflection = $declaredObjectType->getClassReflection();
158154

159-
if ($classReflection === null) {
155+
if (!$classReflection instanceof ClassReflection) {
160156
return false;
161157
}
162158

@@ -168,7 +164,7 @@ private function isActualTypeAnonymous(string $actualType): bool
168164
$actualObjectType = new ObjectType($actualType);
169165
$classReflection = $actualObjectType->getClassReflection();
170166

171-
if ($classReflection === null) {
167+
if (!$classReflection instanceof ClassReflection) {
172168
return false;
173169
}
174170

@@ -218,13 +214,13 @@ private function hasParentMethodWithNonObjectReturn(ClassMethod $classMethod): b
218214

219215
$parentClassMethod = $this->astResolver->resolveClassMethod($ancestor->getName(), $methodName);
220216

221-
if ($parentClassMethod === null) {
217+
if (!$parentClassMethod instanceof ClassMethod) {
222218
continue;
223219
}
224220

225221
$parentReturnType = $parentClassMethod->returnType;
226222

227-
if ($parentReturnType === null) {
223+
if (!$parentReturnType instanceof Node) {
228224
continue;
229225
}
230226

@@ -238,9 +234,9 @@ private function hasParentMethodWithNonObjectReturn(ClassMethod $classMethod): b
238234
return false;
239235
}
240236

241-
private function getActualReturnClass(ClassMethod $node): ?string
237+
private function getActualReturnClass(ClassMethod $classMethod): ?string
242238
{
243-
$returnStatements = $this->betterNodeFinder->findReturnsScoped($node);
239+
$returnStatements = $this->betterNodeFinder->findReturnsScoped($classMethod);
244240

245241
if ($returnStatements === []) {
246242
return null;

0 commit comments

Comments
 (0)