AddExtendsAnnotationToModelFactoriesRector rule are not applying any diff
Closed this issue · 5 comments
I'm trying to use the AddExtendsAnnotationToModelFactoriesRector
to add the @extends
annotation to factory classes, but nothing is applied. Am I missing something?
Factory class database/factories/CategoryFactory.php
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class CategoryFactory extends Factory
{
protected $model = \App\Models\Category::class;
public function definition()
{
return [
'name' => $this->faker->sentence(),
];
}
}
Rector config rector.php
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/database',
]);
// register a single rule
$rectorConfig->rule(RectorLaravel\Rector\Class_\AddExtendsAnnotationToModelFactoriesRector::class);
};
You might need a backslash before the rule name. Maybe.
You might need a backslash before the rule name. Maybe.
Thanks for the reply.
Unfortenly it makes no difference, and neither does importing the class.
The same thing happens in a fresh Laravel install if the @extends
is removed from the default UserFactory
@hmazter In that case I think it's because of the latest Rector release https://github.com/rectorphp/rector/releases/tag/0.18.3, which breaks rules that modify docblocks.
There is a PR to support that release #135, but until it gets merged, you can use a fixed older version of core Rector like 0.18.2: "rector/rector": "0.18.2",
.
Thanks that worked! 👍