Skip to content

Commit 0b44760

Browse files
committed
Updated Rector to commit 3bc3c849b36368f898f9a79ff13a7c9cbed3ddae
rectorphp/rector-src@3bc3c84 Revert goto handling on ExplicitReturnNullRector (#7021)
1 parent decefa6 commit 0b44760

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
use PhpParser\Node\Stmt\Class_;
1212
use PhpParser\Node\Stmt\ClassMethod;
1313
use PhpParser\Node\Stmt\Function_;
14+
use PhpParser\Node\Stmt\Goto_;
1415
use PhpParser\Node\Stmt\Return_;
1516
use PhpParser\NodeVisitor;
1617
use PHPStan\Type\NullType;
1718
use PHPStan\Type\UnionType;
1819
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1920
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
2021
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
22+
use Rector\PhpParser\Node\BetterNodeFinder;
2123
use Rector\Rector\AbstractRector;
2224
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
2325
use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver;
@@ -49,13 +51,18 @@ final class ExplicitReturnNullRector extends AbstractRector
4951
* @readonly
5052
*/
5153
private ReturnTypeInferer $returnTypeInferer;
52-
public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer)
54+
/**
55+
* @readonly
56+
*/
57+
private BetterNodeFinder $betterNodeFinder;
58+
public function __construct(SilentVoidResolver $silentVoidResolver, PhpDocInfoFactory $phpDocInfoFactory, TypeFactory $typeFactory, PhpDocTypeChanger $phpDocTypeChanger, ReturnTypeInferer $returnTypeInferer, BetterNodeFinder $betterNodeFinder)
5359
{
5460
$this->silentVoidResolver = $silentVoidResolver;
5561
$this->phpDocInfoFactory = $phpDocInfoFactory;
5662
$this->typeFactory = $typeFactory;
5763
$this->phpDocTypeChanger = $phpDocTypeChanger;
5864
$this->returnTypeInferer = $returnTypeInferer;
65+
$this->betterNodeFinder = $betterNodeFinder;
5966
}
6067
public function getRuleDefinition() : RuleDefinition
6168
{
@@ -114,6 +121,10 @@ public function refactor(Node $node) : ?Node
114121
if (!$returnType instanceof UnionType) {
115122
return null;
116123
}
124+
$hasGoto = (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($node, fn(Node $node): bool => $node instanceof Goto_);
125+
if ($hasGoto) {
126+
return null;
127+
}
117128
$hasChanged = \false;
118129
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use(&$hasChanged) {
119130
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {

rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use PhpParser\Node\Stmt\Function_;
2626
use PhpParser\Node\Stmt\Goto_;
2727
use PhpParser\Node\Stmt\If_;
28-
use PhpParser\Node\Stmt\Label;
2928
use PhpParser\Node\Stmt\Return_;
3029
use PhpParser\Node\Stmt\Switch_;
3130
use PhpParser\Node\Stmt\TryCatch;
@@ -96,25 +95,13 @@ public function hasSilentVoid(FunctionLike $functionLike) : bool
9695
*/
9796
private function hasStmtsAlwaysReturnOrExit(array $stmts) : bool
9897
{
99-
// early label check position key stmt
100-
// as label can be defined later after goto
101-
$hasAlwaysReturnOrExitAfterLabelPosition = null;
102-
foreach ($stmts as $key => $stmt) {
103-
if ($stmt instanceof Label && isset($stmts[$key + 1]) && $this->hasStmtsAlwaysReturnOrExit(\array_slice($stmts, $key + 1))) {
104-
$hasAlwaysReturnOrExitAfterLabelPosition = $key;
105-
break;
106-
}
107-
}
108-
foreach ($stmts as $key => $stmt) {
98+
foreach ($stmts as $stmt) {
10999
if ($this->neverFuncCallAnalyzer->isWithNeverTypeExpr($stmt)) {
110100
return \true;
111101
}
112102
if ($this->isStopped($stmt)) {
113103
return \true;
114104
}
115-
if ($stmt instanceof Goto_ && $hasAlwaysReturnOrExitAfterLabelPosition < $key) {
116-
return \true;
117-
}
118105
// has switch with always return
119106
if ($stmt instanceof Switch_ && $this->isSwitchWithAlwaysReturnOrExit($stmt)) {
120107
return \true;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '3dacd700b6cf461af650cd2714a460f08cc3d6fb';
22+
public const PACKAGE_VERSION = '3bc3c849b36368f898f9a79ff13a7c9cbed3ddae';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-06-25 16:45:58';
27+
public const RELEASE_DATE = '2025-06-25 16:55:43';
2828
/**
2929
* @var int
3030
*/

vendor/scoper-autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// Restore the backup and ensure the excluded files are properly marked as loaded
1515
$GLOBALS['__composer_autoload_files'] = \array_merge(
1616
$existingComposerAutoloadFiles,
17-
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
17+
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
1818
);
1919

2020
return $loader;

0 commit comments

Comments
 (0)