mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-04 23:52:28 +02:00
Merge pull request #1725 from ravanscafi/empty-compact
Empty compacts are forbidden, keep signature by replacing with empty array
This commit is contained in:
commit
a2e7fbe557
@ -3,6 +3,7 @@
|
||||
namespace Rector\Php\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -78,6 +79,10 @@ CODE_SAMPLE
|
||||
unset($node->args[$key]);
|
||||
}
|
||||
|
||||
if (!$node->args) {
|
||||
return new Array_();
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Php\Tests\Rector\FuncCall\RemoveMissingCompactVariableRector\Fixture;
|
||||
|
||||
class EmptyCompact
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return compact('non_existing');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Php\Tests\Rector\FuncCall\RemoveMissingCompactVariableRector\Fixture;
|
||||
|
||||
class EmptyCompact
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -9,7 +9,11 @@ final class RemoveMissingCompactVariableRectorTest extends AbstractRectorTestCas
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/skip_maybe_defined.inc']);
|
||||
$this->doTestFiles([
|
||||
__DIR__ . '/Fixture/fixture.php.inc',
|
||||
__DIR__ . '/Fixture/empty_compact.php.inc',
|
||||
__DIR__ . '/Fixture/skip_maybe_defined.inc',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
|
Loading…
x
Reference in New Issue
Block a user