Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

newbie111's avatar

Rector PHP - @noRector issue

Any idea why the @noRector doesn't work in this case? It always changes to private, but then the Attribute won't work. Thanks! :)

/**
 * Interact with target's latest post created at.
 *
 * @noRector \Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector
 */
protected function latestPostCreatedAt(): Attribute
{
    return Attribute::make(
        set: fn (string $value): ?Carbon => Carbon::parse($value),
    );
}  		
    ---------- begin diff ----------
@@ @@
      *
      * @noRector \Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector
      */
-    protected function latestPostCreatedAt(): Attribute
+    private function latestPostCreatedAt(): Attribute
     {
         return Attribute::make(
             set: fn (string $value): ?Carbon => Carbon::parse($value),
    ----------- end diff -----------

Applied rules:
 * PrivatizeFinalClassMethodRector
1 like
1 reply
sertxudev's avatar

For anyone who ends up in this post, the @noRector PHPDoc was removed on Rector 0.15.

To skip a rule, you have to use the method withSkip on the rector.php config file.

You can check the PR if you want: https://github.com/rectorphp/rector-src/pull/3148

So to solve the problem stated on the above question, you should modify the rector.php config file to include the following:

->withSkip([
	\Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector::class => [
		'*/Models/*',
	]
])

This will prevent Rector from changing any protected method to private in our models.

2 likes

Please or to participate in this conversation.