-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip void without final keyword in ReturnNeverTypeRector as could be …
…implemented with more precise children (#5379) * Skip void without final keyword in ReturnNeverTypeRector as could be implemented with more precise children * simplify * tidy up * tidy up * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
53ba155
commit 8df2120
Showing
14 changed files
with
121 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ class HasChildrenReturnNeverChild extends HasChildrenReturnNever { | |
} | ||
} | ||
|
||
?> | ||
?> |
31 changes: 31 additions & 0 deletions
31
...tion/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/require_existing_final_void.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\Fixture; | ||
|
||
use Rector\Core\Exception\ShouldNotHappenException; | ||
|
||
final class RequireExistingFinalVoid | ||
{ | ||
public function run(): void | ||
{ | ||
throw new ShouldNotHappenException('implement by child'); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\Fixture; | ||
|
||
use Rector\Core\Exception\ShouldNotHappenException; | ||
|
||
final class RequireExistingFinalVoid | ||
{ | ||
public function run(): never | ||
{ | ||
throw new ShouldNotHappenException('implement by child'); | ||
} | ||
} | ||
|
||
?> |
14 changes: 0 additions & 14 deletions
14
...laration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_conditional_throw3.php.inc
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...peDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_existing_void.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\Fixture; | ||
|
||
use Rector\Core\Exception\ShouldNotHappenException; | ||
|
||
class SkipExistingVoid | ||
{ | ||
public function run(): void | ||
{ | ||
throw new ShouldNotHappenException('implement by child'); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
...ClassMethod/ReturnNeverTypeRector/Fixture/skip_has_children_return_mixed_explicit.php.inc
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...Declaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_method_throwing.php.inc
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...ypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_nested_value.php.inc
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...ests/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_return.php.inc
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...turnNeverTypeRector/Fixture/skip_setters_param_intersection_docblock_not_autoload.php.inc
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
rules/TypeDeclaration/NodeAnalyzer/NeverFuncCallAnalyzer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\TypeDeclaration\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Expr\Closure; | ||
use PhpParser\Node\Stmt; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
use PhpParser\Node\Stmt\Expression; | ||
use PhpParser\Node\Stmt\Function_; | ||
use PHPStan\Type\NeverType; | ||
use Rector\NodeTypeResolver\NodeTypeResolver; | ||
|
||
final class NeverFuncCallAnalyzer | ||
{ | ||
public function __construct( | ||
private readonly NodeTypeResolver $nodeTypeResolver, | ||
) { | ||
} | ||
|
||
public function hasNeverFuncCall(ClassMethod | Closure | Function_ $functionLike): bool | ||
{ | ||
$hasNeverType = false; | ||
|
||
foreach ((array) $functionLike->stmts as $stmt) { | ||
if ($stmt instanceof Expression) { | ||
$stmt = $stmt->expr; | ||
} | ||
|
||
if ($stmt instanceof Stmt) { | ||
continue; | ||
} | ||
|
||
$stmtType = $this->nodeTypeResolver->getNativeType($stmt); | ||
if ($stmtType instanceof NeverType) { | ||
$hasNeverType = true; | ||
} | ||
} | ||
|
||
return $hasNeverType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters