Skip to content

Commit

Permalink
[DX] Add default empty definition on getRuleDefinition() method on Ab…
Browse files Browse the repository at this point in the history
…stractRector
  • Loading branch information
samsonasik committed Nov 16, 2024
1 parent e7800e9 commit 9edf688
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
14 changes: 0 additions & 14 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@
// comment out
str_replace('\\' . $prefix . '\trigger_deprecation(', '// \trigger_deprecation(', $content),

// make external rules easier to write without enforing getRuleDefinition()
// as they are not designed for open-sourcing
static function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with(
$filePath,
'vendor/symplify/rule-doc-generator-contracts/src/Contract/DocumentedRuleInterface.php'
)) {
return $content;
}

// comment out
return str_replace('public function getRuleDefinition', '// public function getRuleDefinition', $content);
},

static function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with($filePath, 'src/Application/VersionResolver.php')) {
return $content;
Expand Down
6 changes: 6 additions & 0 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Rector\PhpParser\Node\NodeFactory;
use Rector\Skipper\Skipper\Skipper;
use Rector\ValueObject\Application\File;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface
{
Expand Down Expand Up @@ -119,6 +120,11 @@ public function beforeTraverse(array $nodes): ?array
return parent::beforeTraverse($nodes);
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('', []);
}

final public function enterNode(Node $node): int|Node|null
{
if (! $this->isMatchingNodeType($node)) {
Expand Down

0 comments on commit 9edf688

Please sign in to comment.