-
-
Notifications
You must be signed in to change notification settings - Fork 670
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
Incorrect behavior of RenameClassRector #7417
Comments
The change is expected, the https://getrector.org/demo/8402e93c-63be-44f0-a7bd-509f904a9061 if you want to skip the $rectorConfig->skip([
RenameClassRector::class => __DIR__ . '/app/Entity'
]); |
Thanks for the reply. The problem is that I want to skip RenameClassRector rule, but event I provide a full path to the file, it isn't skipped: https://getrector.org/demo/94c60b5b-3228-4719-8128-9cec1cf8e7dd |
RenameClassRector seems use post rector, which skip by path may overlapped,
if you don't need, you can skip it entirely without path:
$rectorConfig->skip([
RenameClassRector::class,
//...
]);
Pada tanggal Kam, 25 Agu 2022 15:22, grandmaster44 ***@***.***>
menulis:
… Thanks for the reply.
The problem is that I want to skip RenameClassRector rule, but event I
provide a full path to the file, it isn't skipped:
https://getrector.org/demo/94c60b5b-3228-4719-8128-9cec1cf8e7dd
—
Reply to this email directly, view it on GitHub
<#7417 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADQHAEDKMQIJ252XRSVGT3V24UMXANCNFSM57R7OKHQ>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
see https://getrector.org/demo/4b5954ac-1563-456c-9ad0-f96913f0b784
Pada tanggal Kam, 25 Agu 2022 15:36, abdul malik ikhsan <
***@***.***> menulis:
… RenameClassRector seems use post rector, which skip by path may
overlapped, if you don't need, you can skip it entirely without path:
$rectorConfig->skip([
RenameClassRector::class,
//...
]);
Pada tanggal Kam, 25 Agu 2022 15:22, grandmaster44 <
***@***.***> menulis:
> Thanks for the reply.
>
> The problem is that I want to skip RenameClassRector rule, but event I
> provide a full path to the file, it isn't skipped:
>
> https://getrector.org/demo/94c60b5b-3228-4719-8128-9cec1cf8e7dd
>
> —
> Reply to this email directly, view it on GitHub
> <#7417 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AADQHAEDKMQIJ252XRSVGT3V24UMXANCNFSM57R7OKHQ>
> .
> You are receiving this because you were assigned.Message ID:
> ***@***.***>
>
|
Skipping the RenameClassRector rule is not a solution. I want to rename class in every file except the single one. How can I achieve this ? |
It seems not possible, as now, as it applied in post rector as well, see rector/packages/PostRector/Rector/ClassRenamingPostRector.php Lines 35 to 39 in dbe8618
that's executed if The question is why you're doing that, because changing only in specific file for |
I discovered that I can skip the rule by combination of two rules (RenameClassRector and ClassRenamingPostRector) https://getrector.org/demo/acfd37ce-819f-4248-b13c-e229c438cfa7 <?php
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
use Rector\PostRector\Rector\ClassRenamingPostRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->skip([
TypedPropertyRector::class => ['/rector_analyzed_file.php'],
RenameClassRector::class => ['/rector_analyzed_file.php'],
ClassRenamingPostRector::class => ['/rector_analyzed_file.php'],
]);
$rectorConfig->rule(TypedPropertyRector::class);
$rectorConfig->rule(RemoveUnreachableStatementRector::class);
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
Demo::class => Demo2::class,
]);
}; The reason for skipping a single file from RenameClassRector rule may be that I want to force the usage of NewMailer in new features and thus allow OldMailer to be used in old ones. Old Feature (skip class rename): //@deprecated
final class DeprecatedVendorMailer{}
//@deprecated
final class OldSendMailService {
public function __construct(DeprecatedVendorMailer $mailer) {}
} New Feature (check that NewMailer has been used - if not - rename class - from DeprecatedVendorMailer to NewVendorMailer): final class NewVendorMailer{}
final class NewSendMailService {
public function __construct(NewVendorMailer $mailer) {}
} |
@grandmaster44 awesome 👍 , yes, it seems skip both |
Re-open, I will create PR to properly fix it. |
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.org/demo/224e1a17-d4f4-4d71-bafe-f1d4cf129846
Responsible rules
Expected Behavior
Rector should skip RenameClassRector rule (same as TypedPropertyRector was skipped)
The text was updated successfully, but these errors were encountered: