driftingly / rector-laravel

Rector upgrades rules for Laravel
http://getrector.org
MIT License
469 stars 48 forks source link

Attributes are lost in conversion #212

Closed jeff1326 closed 2 months ago

jeff1326 commented 2 months ago

See output of my dry run below.

58) modules/text_product/Database/factories/SupplierFactory.php:5

    ---------- begin diff ----------
@@ @@
 use TextProduct\Models\Supplier;
 use TextProduct\Models\Country;

-$factory->define(Supplier::class, fn(Faker $faker) => [
-    'name' => $faker->company,
-    'origin_country_id' => Country::factory(),
-    'type' => $faker->numberBetween(1, 3),
-]);
+class SupplierFactory extends \Illuminate\Database\Eloquent\Factories\Factory
+{
+    protected $model = Supplier::class;
+}
    ----------- end diff -----------

Applied rules:
 * FactoryDefinitionRector (https://laravel.com/docs/7.x/database-testing#writing-factories)

Name, origin country id and type are lost in conversion. Note that this is in another folder than a base laravel.

When i converted back the arrow function to anonymous functions (or closure if you prefer this term), this was working as expected.