mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
[CodeQuality][DeadCode] Handle SimplifyUselessVariableRector+RemoveOverriddenValuesRector (#2277)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
e5a45afba3
commit
30f2f91909
|
@ -107,7 +107,7 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function resolveAssignedVariables(FunctionLike $functionLike): array
|
||||
{
|
||||
return $this->betterNodeFinder->find($functionLike, function (Node $node): bool {
|
||||
return $this->betterNodeFinder->find($functionLike, function (Node $node) use ($functionLike): bool {
|
||||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (! $parentNode instanceof Assign) {
|
||||
return false;
|
||||
|
@ -138,6 +138,11 @@ CODE_SAMPLE
|
|||
return false;
|
||||
}
|
||||
|
||||
$parentFunctionLike = $this->betterNodeFinder->findParentType($node, FunctionLike::class);
|
||||
if ($parentFunctionLike !== $functionLike) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! $this->reservedKeywordAnalyzer->isNativeVariable($node->name);
|
||||
});
|
||||
}
|
||||
|
|
49
tests/Issues/UselessVariableOverride/Fixture/fixture.php.inc
Normal file
49
tests/Issues/UselessVariableOverride/Fixture/fixture.php.inc
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\UselessVariableOverride\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
public function formatPlaces($geotools, $places): array
|
||||
{
|
||||
$features = \array_map(function (array $placeResource) use (
|
||||
$geotools
|
||||
) {
|
||||
$distances = \array_map(static function (CoordinateInterface $coordinate) use ($geotools) {
|
||||
return $geotools->distance()->flat();
|
||||
}, []);
|
||||
|
||||
return new Feature($distances);
|
||||
}, $places);
|
||||
|
||||
return $features;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\UselessVariableOverride\Fixture;
|
||||
|
||||
class Fixture
|
||||
{
|
||||
public function formatPlaces($geotools, $places): array
|
||||
{
|
||||
return \array_map(function (array $placeResource) use (
|
||||
$geotools
|
||||
) {
|
||||
$distances = \array_map(static function (CoordinateInterface $coordinate) use ($geotools) {
|
||||
return $geotools->distance()->flat();
|
||||
}, []);
|
||||
|
||||
return new Feature($distances);
|
||||
}, $places);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Tests\Issues\UselessVariableOverride;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class UselessVariableOverrideTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Iterator<SmartFileInfo>
|
||||
*/
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
public function provideConfigFilePath(): string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DeadCode\Rector\FunctionLike\RemoveOverriddenValuesRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->rule(SimplifyUselessVariableRector::class);
|
||||
$rectorConfig->rule(RemoveOverriddenValuesRector::class);
|
||||
};
|
Loading…
Reference in New Issue
Block a user