Skip to content

Commit 84edb4a

Browse files
jivanfGeniJaho
andauthored
Make RemoveDumpDataDeadCodeRector rule configurable (#258)
Co-authored-by: Geni Jaho <[email protected]>
1 parent 3fbbe3f commit 84edb4a

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docs/rector_rules_overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ refactors calls with the pre Laravel 11 methods for blueprint geometry columns
978978

979979
It will removes the dump data just like dd or dump functions from the code.`
980980

981+
:wrench: **configure it!**
982+
981983
- class: [`RectorLaravel\Rector\FuncCall\RemoveDumpDataDeadCodeRector`](../src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php)
982984

983985
```diff

src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
use PhpParser\Node\Expr\FuncCall;
99
use PhpParser\Node\Stmt\Expression;
1010
use PhpParser\NodeTraverser;
11+
use Rector\Contract\Rector\ConfigurableRectorInterface;
1112
use Rector\Rector\AbstractRector;
1213
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1314
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
15+
use Webmozart\Assert\Assert;
1416

1517
/**
1618
* @see \RectorLaravel\Tests\Rector\FuncCall\RemoveDumpDataDeadCodeRector\RemoveDumpDataDeadCodeRectorTest
1719
*/
18-
final class RemoveDumpDataDeadCodeRector extends AbstractRector
20+
final class RemoveDumpDataDeadCodeRector extends AbstractRector implements ConfigurableRectorInterface
1921
{
22+
/**
23+
* @var string[]
24+
*/
25+
private array $dumpFunctionNames = ['dd', 'dump'];
26+
2027
public function getRuleDefinition(): RuleDefinition
2128
{
2229
return new RuleDefinition(
@@ -76,10 +83,20 @@ public function refactor(Node $node): int|Node|array|null
7683
return null;
7784
}
7885

79-
if (! $this->isNames($node->expr->name, ['dd', 'dump'])) {
86+
if (! $this->isNames($node->expr->name, $this->dumpFunctionNames)) {
8087
return null;
8188
}
8289

8390
return NodeTraverser::REMOVE_NODE;
8491
}
92+
93+
/**
94+
* @param mixed[] $configuration
95+
*/
96+
public function configure(array $configuration): void
97+
{
98+
Assert::allString($configuration);
99+
100+
$this->dumpFunctionNames = $configuration;
101+
}
85102
}

tests/Rector/FuncCall/RemoveDumpDataDeadCodeRector/config/configured_rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
return static function (RectorConfig $rectorConfig): void {
99
$rectorConfig->import(__DIR__ . '/../../../../../config/config.php');
1010

11-
$rectorConfig->rule(RemoveDumpDataDeadCodeRector::class);
11+
$rectorConfig->ruleWithConfiguration(RemoveDumpDataDeadCodeRector::class, ['dd', 'dump']);
1212
};

0 commit comments

Comments
 (0)