From 9edf68820178c7ba4b42152ddec94413748e3742 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 16 Nov 2024 22:29:37 +0700 Subject: [PATCH] [DX] Add default empty definition on getRuleDefinition() method on AbstractRector --- scoper.php | 14 -------------- src/Rector/AbstractRector.php | 6 ++++++ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/scoper.php b/scoper.php index c1def570660..cadca20a6f7 100644 --- a/scoper.php +++ b/scoper.php @@ -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; diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index b0d6e2465b4..8b1285789d1 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -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 { @@ -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)) {