Skip to content

Commit ba32665

Browse files
committed
Updated Rector to commit 4997962de1f53c449dadbef7025bffe5ca41e63c
rectorphp/rector-src@4997962 Bump PHPStan to 2.1.38 (#7879)
1 parent e57d1c8 commit ba32665

5 files changed

Lines changed: 51 additions & 53 deletions

File tree

vendor/composer/installed.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,12 +1818,12 @@
18181818
"source": {
18191819
"type": "git",
18201820
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
1821-
"reference": "f73e3378da838b801b632c4418ae5cc3363f228f"
1821+
"reference": "338187c0cb94e5c65e88233239ca94b146555703"
18221822
},
18231823
"dist": {
18241824
"type": "zip",
1825-
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/f73e3378da838b801b632c4418ae5cc3363f228f",
1826-
"reference": "f73e3378da838b801b632c4418ae5cc3363f228f",
1825+
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/338187c0cb94e5c65e88233239ca94b146555703",
1826+
"reference": "338187c0cb94e5c65e88233239ca94b146555703",
18271827
"shasum": ""
18281828
},
18291829
"require": {
@@ -1850,7 +1850,7 @@
18501850
"tomasvotruba\/unused-public": "^2.2",
18511851
"tracy\/tracy": "^2.11"
18521852
},
1853-
"time": "2026-02-04T15:53:00+00:00",
1853+
"time": "2026-02-04T16:21:36+00:00",
18541854
"default-branch": true,
18551855
"type": "rector-extension",
18561856
"extra": {

vendor/composer/installed.php

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

vendor/rector/extension-installer/src/GeneratedConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
final class GeneratedConfig
1111
{
12-
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 46e4f77'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main a110e2f'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main f73e337'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main eadb590'));
12+
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 46e4f77'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main a110e2f'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 338187c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main eadb590'));
1313
private function __construct()
1414
{
1515
}

vendor/rector/rector-phpunit/rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace Rector\PHPUnit\CodeQuality\NodeAnalyser;
55

66
use PhpParser\Node\Expr;
7-
use PhpParser\Node\Expr\Array_;
8-
use PhpParser\Node\Expr\CallLike;
97
use PhpParser\Node\Expr\MethodCall;
108
use PhpParser\Node\Expr\PropertyFetch;
119
use PhpParser\Node\Expr\Variable;
@@ -95,38 +93,4 @@ public function isPropertyUsedForMocking(Class_ $class, string $propertyName): b
9593
}
9694
return \false;
9795
}
98-
public function isPropertyMockObjectPassedAsArgument(Class_ $class, string $propertyName): bool
99-
{
100-
/** @var array<Expr\CallLike> $callLikes */
101-
$callLikes = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), [CallLike::class]);
102-
foreach ($callLikes as $callLike) {
103-
if ($callLike->isFirstClassCallable()) {
104-
continue;
105-
}
106-
foreach ($callLike->getArgs() as $arg) {
107-
if (!$arg->value instanceof PropertyFetch) {
108-
continue;
109-
}
110-
$propertyFetch = $arg->value;
111-
// its used in arg
112-
if ($this->nodeNameResolver->isName($propertyFetch->name, $propertyName)) {
113-
return \true;
114-
}
115-
}
116-
}
117-
/** @var array<Array_> $arrays */
118-
$arrays = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), [Array_::class]);
119-
foreach ($arrays as $array) {
120-
foreach ($array->items as $arrayItem) {
121-
if (!$arrayItem->value instanceof PropertyFetch) {
122-
continue;
123-
}
124-
$propertyFetch = $arrayItem->value;
125-
if ($this->nodeNameResolver->isName($propertyFetch->name, $propertyName)) {
126-
return \true;
127-
}
128-
}
129-
}
130-
return \false;
131-
}
13296
}

vendor/rector/rector-phpunit/rules/CodeQuality/Rector/Class_/RemoveNeverUsedMockPropertyRector.php

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use PhpParser\Node\Stmt\ClassMethod;
1212
use PhpParser\Node\Stmt\Expression;
1313
use PhpParser\Node\Stmt\Property;
14-
use Rector\PHPUnit\CodeQuality\NodeAnalyser\MockObjectExprDetector;
14+
use Rector\PhpParser\Node\BetterNodeFinder;
15+
use Rector\PhpParser\NodeFinder\PropertyFetchFinder;
1516
use Rector\PHPUnit\CodeQuality\NodeAnalyser\MockObjectPropertyDetector;
1617
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1718
use Rector\Rector\AbstractRector;
@@ -34,12 +35,17 @@ final class RemoveNeverUsedMockPropertyRector extends AbstractRector
3435
/**
3536
* @readonly
3637
*/
37-
private MockObjectExprDetector $mockObjectExprDetector;
38-
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, MockObjectPropertyDetector $mockObjectPropertyDetector, MockObjectExprDetector $mockObjectExprDetector)
38+
private PropertyFetchFinder $propertyFetchFinder;
39+
/**
40+
* @readonly
41+
*/
42+
private BetterNodeFinder $betterNodeFinder;
43+
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, MockObjectPropertyDetector $mockObjectPropertyDetector, PropertyFetchFinder $propertyFetchFinder, BetterNodeFinder $betterNodeFinder)
3944
{
4045
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
4146
$this->mockObjectPropertyDetector = $mockObjectPropertyDetector;
42-
$this->mockObjectExprDetector = $mockObjectExprDetector;
47+
$this->propertyFetchFinder = $propertyFetchFinder;
48+
$this->betterNodeFinder = $betterNodeFinder;
4349
}
4450
public function getRuleDefinition(): RuleDefinition
4551
{
@@ -95,13 +101,7 @@ public function refactor(Node $node): ?Node
95101
if ($propertyNamesToCreateMockMethodCalls === []) {
96102
return null;
97103
}
98-
$propertyNamesToRemove = [];
99-
foreach (array_keys($propertyNamesToCreateMockMethodCalls) as $propertyName) {
100-
if ($this->mockObjectExprDetector->isPropertyMockObjectPassedAsArgument($node, $propertyName)) {
101-
continue;
102-
}
103-
$propertyNamesToRemove[] = $propertyName;
104-
}
104+
$propertyNamesToRemove = $this->resolvePropertyNamesToRemove($propertyNamesToCreateMockMethodCalls, $node);
105105
if ($propertyNamesToRemove === []) {
106106
return null;
107107
}
@@ -171,4 +171,38 @@ private function removePropertyFromClass(Class_ $class, string $propertyNameToRe
171171
unset($class->stmts[$key]);
172172
}
173173
}
174+
/**
175+
* @param array<string, MethodCall> $propertyNamesToCreateMockMethodCalls
176+
* @return string[]
177+
*/
178+
private function resolvePropertyNamesToRemove(array $propertyNamesToCreateMockMethodCalls, Class_ $class): array
179+
{
180+
$propertyNamesToRemove = [];
181+
foreach (array_keys($propertyNamesToCreateMockMethodCalls) as $propertyName) {
182+
$allPropertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $propertyName);
183+
/** @var MethodCall[] $methodCalls */
184+
$methodCalls = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), MethodCall::class);
185+
$propertyFetchesMethodCalls = [];
186+
foreach ($methodCalls as $methodCall) {
187+
if ($methodCall->isFirstClassCallable()) {
188+
continue;
189+
}
190+
if (!$methodCall->var instanceof PropertyFetch) {
191+
continue;
192+
}
193+
$propertyFetch = $methodCall->var;
194+
if (!$this->isName($propertyFetch->name, $propertyName)) {
195+
continue;
196+
}
197+
// used in method call, skip removal
198+
$propertyFetchesMethodCalls[] = $methodCall;
199+
}
200+
// -1 for the assign in setUp() method
201+
if (count($allPropertyFetches) - 1 !== count($propertyFetchesMethodCalls)) {
202+
continue;
203+
}
204+
$propertyNamesToRemove[] = $propertyName;
205+
}
206+
return $propertyNamesToRemove;
207+
}
174208
}

0 commit comments

Comments
 (0)