Skip to content

Commit 549dae3

Browse files
committed
Updated Rector to commit 1d87f5ab1f4f0845f668581c53dd24ac13d05267
rectorphp/rector-src@1d87f5a Revert "[Experiment][Printer] Move AlwaysRememberedExpr tweak logic to separa…" (#7672)
1 parent 98a9eec commit 549dae3

File tree

10 files changed

+154
-30
lines changed

10 files changed

+154
-30
lines changed

.github/workflows/stale.yaml.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Close stale issues and PRs"
2+
3+
on:
4+
schedule:
5+
# runs daily at midnight
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
stale:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/stale@v10
13+
with:
14+
days-before-stale: 60
15+
days-before-close: 90
16+
stale-issue-message: 'This issue has been automatically marked as stale due to inactivity. It will be closed in next 30 days if no further activity occurs.'
17+
close-issue-message: 'Closing this issue due to prolonged inactivity.'

.github/workflows/tweet_release.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ public function refactor(Node $node): ?Node
7171
if (!$firstArgValue instanceof Array_) {
7272
return null;
7373
}
74+
// remove first arg
75+
$originalArgs = $node->getArgs();
76+
array_shift($originalArgs);
7477
$methodCall = $this->arrayCallableToMethodCallFactory->create($firstArgValue);
7578
if (!$methodCall instanceof MethodCall) {
7679
return null;
7780
}
78-
$originalArgs = $node->args;
79-
unset($originalArgs[0]);
8081
$methodCall->args = $originalArgs;
8182
return $methodCall;
8283
}

rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function refactor(Node $node): ?Node
101101
if (!$hasChanged) {
102102
return null;
103103
}
104+
// update array keys to fit printer
105+
$node->stmts = array_values($node->stmts);
104106
return $node;
105107
}
106108
private function isSelfReferencing(Assign $assign): bool
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\DeadCode\Rector\Stmt;
5+
6+
use PhpParser\Node;
7+
use PhpParser\Node\Expr\Variable;
8+
use PhpParser\Node\Stmt\If_;
9+
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
10+
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
11+
use Rector\PhpParser\Node\BetterNodeFinder;
12+
use Rector\Rector\AbstractRector;
13+
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
14+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
15+
/**
16+
* @see \Rector\Tests\DeadCode\Rector\Stmt\RemoveNextSameValueConditionRector\RemoveNextSameValueConditionRectorTest
17+
*/
18+
final class RemoveNextSameValueConditionRector extends AbstractRector
19+
{
20+
/**
21+
* @readonly
22+
*/
23+
private SideEffectNodeDetector $sideEffectNodeDetector;
24+
/**
25+
* @readonly
26+
*/
27+
private BetterNodeFinder $betterNodeFinder;
28+
public function __construct(SideEffectNodeDetector $sideEffectNodeDetector, BetterNodeFinder $betterNodeFinder)
29+
{
30+
$this->sideEffectNodeDetector = $sideEffectNodeDetector;
31+
$this->betterNodeFinder = $betterNodeFinder;
32+
}
33+
public function getRuleDefinition(): RuleDefinition
34+
{
35+
return new RuleDefinition('Remove already checked if condition repeated in the very next stmt', [new CodeSample(<<<'CODE_SAMPLE'
36+
final class SomeClass
37+
{
38+
public function __construct(array $items)
39+
{
40+
$count = 100;
41+
if ($items === []) {
42+
$count = 0;
43+
}
44+
45+
if ($items === []) {
46+
return $count;
47+
}
48+
}
49+
}
50+
CODE_SAMPLE
51+
, <<<'CODE_SAMPLE'
52+
final class SomeClass
53+
{
54+
public function __construct(array $items)
55+
{
56+
$count = 100;
57+
if ($items === []) {
58+
$count = 0;
59+
return $count;
60+
}
61+
}
62+
}
63+
CODE_SAMPLE
64+
)]);
65+
}
66+
/**
67+
* @return array<class-string<Node>>
68+
*/
69+
public function getNodeTypes(): array
70+
{
71+
return [StmtsAwareInterface::class];
72+
}
73+
/**
74+
* @param StmtsAwareInterface $node
75+
*/
76+
public function refactor(Node $node): ?Node
77+
{
78+
if ($node->stmts === null) {
79+
return null;
80+
}
81+
foreach ($node->stmts as $key => $stmt) {
82+
if (!$stmt instanceof If_) {
83+
continue;
84+
}
85+
// first condition must be without side effect
86+
if ($this->sideEffectNodeDetector->detect($stmt->cond)) {
87+
continue;
88+
}
89+
if ($this->isCondVariableUsedInIfBody($stmt)) {
90+
continue;
91+
}
92+
$nextStmt = $node->stmts[$key + 1] ?? null;
93+
if (!$nextStmt instanceof If_) {
94+
continue;
95+
}
96+
if (!$this->nodeComparator->areNodesEqual($stmt->cond, $nextStmt->cond)) {
97+
continue;
98+
}
99+
$stmt->stmts = array_merge($stmt->stmts, $nextStmt->stmts);
100+
// remove next node
101+
unset($node->stmts[$key + 1]);
102+
return $node;
103+
}
104+
return null;
105+
}
106+
private function isCondVariableUsedInIfBody(If_ $if): bool
107+
{
108+
$condVariables = $this->betterNodeFinder->findInstancesOf($if->cond, [Variable::class]);
109+
foreach ($condVariables as $condVariable) {
110+
$condVariableName = $this->getName($condVariable);
111+
if ($condVariableName === null) {
112+
continue;
113+
}
114+
if ($this->betterNodeFinder->findVariableOfName($if->stmts, $condVariableName) instanceof Variable) {
115+
return \true;
116+
}
117+
}
118+
return \false;
119+
}
120+
}

rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function getNodeTypes(): array
5050
*/
5151
public function refactor(Node $node): ?Node
5252
{
53+
// Cannot handle variadic args
5354
if ($node->isFirstClassCallable()) {
5455
return null;
5556
}
@@ -89,11 +90,16 @@ private function removeContextArg($callLike): bool
8990
return \false;
9091
}
9192
unset($callLike->args[3 + $methodArgCorrection]);
93+
// update indexed to make printer work as expected
94+
$callLike->args = array_values($callLike->args);
9295
return \true;
9396
}
97+
// process named arguments
9498
foreach ($args as $position => $arg) {
9599
if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) {
96100
unset($callLike->args[$position]);
101+
// update indexed to make printer work as expected
102+
$callLike->args = array_values($callLike->args);
97103
return \true;
98104
}
99105
}

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 = '440d6d76b6b513f8943aee715c5349496a035b44';
22+
public const PACKAGE_VERSION = '1d87f5ab1f4f0845f668581c53dd24ac13d05267';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-11-26 12:11:26';
27+
public const RELEASE_DATE = '2025-11-27 12:15:02';
2828
/**
2929
* @var int
3030
*/

src/Config/Level/DeadCodeLevel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ final class DeadCodeLevel
9797
RemoveUselessAssignFromPropertyPromotionRector::class,
9898
RemoveConcatAutocastRector::class,
9999
SimplifyIfElseWithSameContentRector::class,
100+
// needs more testing, Nov 2025
101+
// RemoveNextSameValueConditionRector::class,
100102
SimplifyUselessVariableRector::class,
101103
RemoveDeadZeroAndOneOperationRector::class,
102104
// docblock

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@
14151415
'Rector\\DeadCode\\Rector\\Return_\\RemoveDeadConditionAboveReturnRector' => $baseDir . '/rules/DeadCode/Rector/Return_/RemoveDeadConditionAboveReturnRector.php',
14161416
'Rector\\DeadCode\\Rector\\StaticCall\\RemoveParentCallWithoutParentRector' => $baseDir . '/rules/DeadCode/Rector/StaticCall/RemoveParentCallWithoutParentRector.php',
14171417
'Rector\\DeadCode\\Rector\\Stmt\\RemoveConditionExactReturnRector' => $baseDir . '/rules/DeadCode/Rector/Stmt/RemoveConditionExactReturnRector.php',
1418+
'Rector\\DeadCode\\Rector\\Stmt\\RemoveNextSameValueConditionRector' => $baseDir . '/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php',
14181419
'Rector\\DeadCode\\Rector\\Stmt\\RemoveUnreachableStatementRector' => $baseDir . '/rules/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector.php',
14191420
'Rector\\DeadCode\\Rector\\Switch_\\RemoveDuplicatedCaseInSwitchRector' => $baseDir . '/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php',
14201421
'Rector\\DeadCode\\Rector\\Ternary\\TernaryToBooleanOrFalseToBooleanAndRector' => $baseDir . '/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ class ComposerStaticInita7e267cdc27b27e669e2bfb1953e23ac
16631663
'Rector\\DeadCode\\Rector\\Return_\\RemoveDeadConditionAboveReturnRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Return_/RemoveDeadConditionAboveReturnRector.php',
16641664
'Rector\\DeadCode\\Rector\\StaticCall\\RemoveParentCallWithoutParentRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/StaticCall/RemoveParentCallWithoutParentRector.php',
16651665
'Rector\\DeadCode\\Rector\\Stmt\\RemoveConditionExactReturnRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Stmt/RemoveConditionExactReturnRector.php',
1666+
'Rector\\DeadCode\\Rector\\Stmt\\RemoveNextSameValueConditionRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php',
16661667
'Rector\\DeadCode\\Rector\\Stmt\\RemoveUnreachableStatementRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Stmt/RemoveUnreachableStatementRector.php',
16671668
'Rector\\DeadCode\\Rector\\Switch_\\RemoveDuplicatedCaseInSwitchRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php',
16681669
'Rector\\DeadCode\\Rector\\Ternary\\TernaryToBooleanOrFalseToBooleanAndRector' => __DIR__ . '/../..' . '/rules/DeadCode/Rector/Ternary/TernaryToBooleanOrFalseToBooleanAndRector.php',

0 commit comments

Comments
 (0)