Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dx] Allow external rules without getRuleDefinition() to make them easier to write #6438

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasVotruba instead of commenting out, I think it is better to have default empty getRuleDefinition in AbstractRector, eg:

abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface
{
    public function getRuleDefinition(): RuleDefinition
    {
        return new RuleDefinition('', []);
    }
}

wdyt? It doesn't enforce user to create it, but can create if they want to :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},

static function (string $filePath, string $prefix, string $content): string {
if (! \str_ends_with($filePath, 'src/Application/VersionResolver.php')) {
return $content;
Expand Down
2 changes: 0 additions & 2 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\Reflection\BetterReflection\SourceLocator\CachingVisitor;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Application\ChangedNodeScopeRefresher;
use Rector\Application\FileProcessor;
Expand Down Expand Up @@ -318,7 +317,6 @@ final class LazyContainerFactory
TypeNodeResolver::class,
NodeScopeResolver::class,
ReflectionProvider::class,
CachingVisitor::class,
];

/**
Expand Down