From 6225519c3385581befdb6a9b8af2406ac5963dc5 Mon Sep 17 00:00:00 2001 From: Nathan E Date: Thu, 10 Sep 2020 13:19:51 -0400 Subject: [PATCH 1/4] chore: seeders --- .../Generators/SeederGeneratorTest.php | 24 +++++++++---------- ...tSeeder.php => CommentSeeder-laravel8.php} | 5 +++- tests/fixtures/seeders/CommentSeeder.php | 5 +--- ...PostSeeder.php => PostSeeder-laravel8.php} | 5 +++- tests/fixtures/seeders/PostSeeder.php | 5 +--- 5 files changed, 22 insertions(+), 22 deletions(-) rename tests/fixtures/seeders/{no-factory/CommentSeeder.php => CommentSeeder-laravel8.php} (65%) rename tests/fixtures/seeders/{no-factory/PostSeeder.php => PostSeeder-laravel8.php} (68%) diff --git a/tests/Feature/Generators/SeederGeneratorTest.php b/tests/Feature/Generators/SeederGeneratorTest.php index b015a48f..2a68e227 100644 --- a/tests/Feature/Generators/SeederGeneratorTest.php +++ b/tests/Feature/Generators/SeederGeneratorTest.php @@ -60,9 +60,9 @@ public function output_generates_seeders() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); + ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder-laravel8.php')); $this->files->expects('put') - ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); + ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -81,9 +81,9 @@ public function output_generates_seeders_l7() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/no-factory/PostSeeder.php')); + ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); $this->files->expects('put') - ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/no-factory/CommentSeeder.php')); + ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -102,9 +102,9 @@ public function output_generates_seeders_l6() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/no-factory/PostSeeder.php')); + ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); $this->files->expects('put') - ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/no-factory/CommentSeeder.php')); + ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -123,9 +123,9 @@ public function output_generates_seeders_from_traced_models() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); + ->with('database/seeders/PostSeeder.php', $this->fixture('seeders/PostSeeder-laravel8.php')); $this->files->expects('put') - ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); + ->with('database/seeders/CommentSeeder.php', $this->fixture('seeders/CommentSeeder-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens)->toArray(); @@ -147,9 +147,9 @@ public function output_generates_seeders_from_traced_models_l7() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/no-factory/PostSeeder.php')); + ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); $this->files->expects('put') - ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/no-factory/CommentSeeder.php')); + ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens)->toArray(); @@ -171,9 +171,9 @@ public function output_generates_seeders_from_traced_models_l6() ->andReturn($this->stub($this->seederStub)); $this->files->expects('put') - ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/no-factory/PostSeeder.php')); + ->with('database/seeds/PostSeeder.php', $this->fixture('seeders/PostSeeder.php')); $this->files->expects('put') - ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/no-factory/CommentSeeder.php')); + ->with('database/seeds/CommentSeeder.php', $this->fixture('seeders/CommentSeeder.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/seeders.yaml')); $tree = $this->blueprint->analyze($tokens)->toArray(); diff --git a/tests/fixtures/seeders/no-factory/CommentSeeder.php b/tests/fixtures/seeders/CommentSeeder-laravel8.php similarity index 65% rename from tests/fixtures/seeders/no-factory/CommentSeeder.php rename to tests/fixtures/seeders/CommentSeeder-laravel8.php index 63a631d8..9f9dc817 100644 --- a/tests/fixtures/seeders/no-factory/CommentSeeder.php +++ b/tests/fixtures/seeders/CommentSeeder-laravel8.php @@ -1,5 +1,8 @@ create(); + Comment::factory()->times(5)->create(); } } diff --git a/tests/fixtures/seeders/CommentSeeder.php b/tests/fixtures/seeders/CommentSeeder.php index 9f9dc817..63a631d8 100644 --- a/tests/fixtures/seeders/CommentSeeder.php +++ b/tests/fixtures/seeders/CommentSeeder.php @@ -1,8 +1,5 @@ times(5)->create(); + factory(\App\Blog\Comment::class, 5)->create(); } } diff --git a/tests/fixtures/seeders/no-factory/PostSeeder.php b/tests/fixtures/seeders/PostSeeder-laravel8.php similarity index 68% rename from tests/fixtures/seeders/no-factory/PostSeeder.php rename to tests/fixtures/seeders/PostSeeder-laravel8.php index 7e085018..438afb19 100644 --- a/tests/fixtures/seeders/no-factory/PostSeeder.php +++ b/tests/fixtures/seeders/PostSeeder-laravel8.php @@ -1,5 +1,8 @@ create(); + Post::factory()->times(5)->create(); } } diff --git a/tests/fixtures/seeders/PostSeeder.php b/tests/fixtures/seeders/PostSeeder.php index 438afb19..7e085018 100644 --- a/tests/fixtures/seeders/PostSeeder.php +++ b/tests/fixtures/seeders/PostSeeder.php @@ -1,8 +1,5 @@ times(5)->create(); + factory(\App\Post::class, 5)->create(); } } From faa1a1d7601735aa492137f2bf2225a3a247a8b2 Mon Sep 17 00:00:00 2001 From: Nathan E Date: Thu, 10 Sep 2020 13:46:46 -0400 Subject: [PATCH 2/4] chore: models --- .../Feature/Generators/ModelGeneratorTest.php | 60 +++++++++++++------ ...s.php => alias-relationships-laravel8.php} | 3 + tests/fixtures/models/alias-relationships.php | 3 - ...ypes.php => all-column-types-laravel8.php} | 3 + tests/fixtures/models/all-column-types.php | 3 - ...tificate-pascal-case-example-laravel8.php} | 3 + .../certificate-pascal-case-example.php | 3 - ...ate-type-pascal-case-example-laravel8.php} | 3 + .../certificate-type-pascal-case-example.php | 3 - .../comment.php => comment-laravel8.php} | 3 +- tests/fixtures/models/comment.php | 3 +- ...p => custom-models-namespace-laravel8.php} | 3 +- .../models/custom-models-namespace.php | 3 +- ...p => custom-pivot-table-name-laravel8.php} | 3 + .../models/custom-pivot-table-name.php | 3 - ....php => disable-auto-columns-laravel8.php} | 3 + ... disable-auto-columns-phpdoc-laravel8.php} | 3 + .../models/disable-auto-columns-phpdoc.php | 3 - .../fixtures/models/disable-auto-columns.php | 3 - ...foreign-key-shorthand-phpdoc-laravel8.php} | 3 + .../models/foreign-key-shorthand-phpdoc.php | 3 - ...age-polymorphic-relationship-laravel8.php} | 3 + .../models/image-polymorphic-relationship.php | 3 - ...ured.php => model-configured-laravel8.php} | 3 + tests/fixtures/models/model-configured.php | 3 - ...guarded.php => model-guarded-laravel8.php} | 3 + tests/fixtures/models/model-guarded.php | 3 - ...s.php => model-relationships-laravel8.php} | 3 + tests/fixtures/models/model-relationships.php | 3 - ...nts.php => nested-components-laravel8.php} | 3 + tests/fixtures/models/nested-components.php | 3 - ...ost-polymorphic-relationship-laravel8.php} | 3 + .../models/post-polymorphic-relationship.php | 3 - ...xample.php => readme-example-laravel8.php} | 3 + ...php => readme-example-phpdoc-laravel8.php} | 3 + .../fixtures/models/readme-example-phpdoc.php | 3 - tests/fixtures/models/readme-example.php | 3 - ...onships.php => relationships-laravel8.php} | 3 + ....php => relationships-phpdoc-laravel8.php} | 3 + .../fixtures/models/relationships-phpdoc.php | 3 - tests/fixtures/models/relationships.php | 3 - ...s.php => resource-statements-laravel8.php} | 3 + tests/fixtures/models/resource-statements.php | 3 - ...-deletes.php => soft-deletes-laravel8.php} | 3 +- ...c.php => soft-deletes-phpdoc-laravel8.php} | 3 +- tests/fixtures/models/soft-deletes-phpdoc.php | 3 +- tests/fixtures/models/soft-deletes.php | 3 +- ...tional.php => unconventional-laravel8.php} | 3 + tests/fixtures/models/unconventional.php | 3 - ...ser-polymorphic-relationship-laravel8.php} | 3 + .../models/user-polymorphic-relationship.php | 3 - 51 files changed, 118 insertions(+), 92 deletions(-) rename tests/fixtures/models/{no-factory/alias-relationships.php => alias-relationships-laravel8.php} (90%) rename tests/fixtures/models/{no-factory/all-column-types.php => all-column-types-laravel8.php} (96%) rename tests/fixtures/models/{no-factory/certificate-pascal-case-example.php => certificate-pascal-case-example-laravel8.php} (91%) rename tests/fixtures/models/{no-factory/certificate-type-pascal-case-example.php => certificate-type-pascal-case-example-laravel8.php} (87%) rename tests/fixtures/models/{no-factory/comment.php => comment-laravel8.php} (82%) rename tests/fixtures/models/{no-factory/custom-models-namespace.php => custom-models-namespace-laravel8.php} (85%) rename tests/fixtures/models/{no-factory/custom-pivot-table-name.php => custom-pivot-table-name-laravel8.php} (89%) rename tests/fixtures/models/{no-factory/disable-auto-columns.php => disable-auto-columns-laravel8.php} (88%) rename tests/fixtures/models/{no-factory/disable-auto-columns-phpdoc.php => disable-auto-columns-phpdoc-laravel8.php} (89%) rename tests/fixtures/models/{no-factory/foreign-key-shorthand-phpdoc.php => foreign-key-shorthand-phpdoc-laravel8.php} (94%) rename tests/fixtures/models/{no-factory/image-polymorphic-relationship.php => image-polymorphic-relationship-laravel8.php} (86%) rename tests/fixtures/models/{no-factory/model-configured.php => model-configured-laravel8.php} (90%) rename tests/fixtures/models/{no-factory/model-guarded.php => model-guarded-laravel8.php} (83%) rename tests/fixtures/models/{no-factory/model-relationships.php => model-relationships-laravel8.php} (92%) rename tests/fixtures/models/{no-factory/nested-components.php => nested-components-laravel8.php} (88%) rename tests/fixtures/models/{no-factory/post-polymorphic-relationship.php => post-polymorphic-relationship-laravel8.php} (86%) rename tests/fixtures/models/{no-factory/readme-example.php => readme-example-laravel8.php} (90%) rename tests/fixtures/models/{no-factory/readme-example-phpdoc.php => readme-example-phpdoc-laravel8.php} (93%) rename tests/fixtures/models/{no-factory/relationships.php => relationships-laravel8.php} (89%) rename tests/fixtures/models/{no-factory/relationships-phpdoc.php => relationships-phpdoc-laravel8.php} (92%) rename tests/fixtures/models/{no-factory/resource-statements.php => resource-statements-laravel8.php} (88%) rename tests/fixtures/models/{no-factory/soft-deletes.php => soft-deletes-laravel8.php} (86%) rename tests/fixtures/models/{no-factory/soft-deletes-phpdoc.php => soft-deletes-phpdoc-laravel8.php} (90%) rename tests/fixtures/models/{no-factory/unconventional.php => unconventional-laravel8.php} (90%) rename tests/fixtures/models/{no-factory/user-polymorphic-relationship.php => user-polymorphic-relationship-laravel8.php} (86%) diff --git a/tests/Feature/Generators/ModelGeneratorTest.php b/tests/Feature/Generators/ModelGeneratorTest.php index 4a67e60a..fae6ed35 100644 --- a/tests/Feature/Generators/ModelGeneratorTest.php +++ b/tests/Feature/Generators/ModelGeneratorTest.php @@ -47,7 +47,7 @@ public function output_generates_nothing_for_empty_tree() /** * @test * @environment-setup useLaravel8 - * @dataProvider modelTreeDataProvider + * @dataProvider laravel8ModelTreeDataProvider */ public function output_generates_models($definition, $path, $model) { @@ -138,7 +138,7 @@ public function output_generates_models_l7($definition, $path, $model) ->with(dirname($path)) ->andReturnTrue(); $this->files->expects('put') - ->with($path, $this->fixture(str_replace('models', 'models/no-factory', $model))); + ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); $tree = $this->blueprint->analyze($tokens); @@ -189,7 +189,7 @@ public function output_generates_models_l6($definition, $path, $model) ->with(dirname($path)) ->andReturnTrue(); $this->files->expects('put') - ->with($path, $this->fixture(str_replace('models', 'models/no-factory', $model))); + ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); $tree = $this->blueprint->analyze($tokens); @@ -229,13 +229,13 @@ public function output_works_for_pascal_case_definition() ->with(dirname($certificateModel)) ->andReturnTrue(); $this->files->expects('put') - ->with($certificateModel, $this->fixture('models/certificate-pascal-case-example.php')); + ->with($certificateModel, $this->fixture('models/certificate-pascal-case-example-laravel8.php')); $this->files->expects('exists') ->with(dirname($certificateTypeModel)) ->andReturnTrue(); $this->files->expects('put') - ->with($certificateTypeModel, $this->fixture('models/certificate-type-pascal-case-example.php')); + ->with($certificateTypeModel, $this->fixture('models/certificate-type-pascal-case-example-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/pascal-case.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -266,7 +266,7 @@ public function output_generates_relationships() ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/Subscription.php', $this->fixture('models/model-relationships.php')); + ->with('app/Subscription.php', $this->fixture('models/model-relationships-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-relationships.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -300,19 +300,19 @@ public function output_generates_polymorphic_relationships() ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/Post.php', $this->fixture('models/post-polymorphic-relationship.php')); + ->with('app/Post.php', $this->fixture('models/post-polymorphic-relationship-laravel8.php')); $this->files->expects('exists') ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/User.php', $this->fixture('models/user-polymorphic-relationship.php')); + ->with('app/User.php', $this->fixture('models/user-polymorphic-relationship-laravel8.php')); $this->files->expects('exists') ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/Image.php', $this->fixture('models/image-polymorphic-relationship.php')); + ->with('app/Image.php', $this->fixture('models/image-polymorphic-relationship-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -346,7 +346,7 @@ public function output_generates_disabled_auto_columns() ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/State.php', $this->fixture('models/disable-auto-columns.php')); + ->with('app/State.php', $this->fixture('models/disable-auto-columns-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/disable-auto-columns.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -386,7 +386,7 @@ public function output_respects_configuration() $this->files->expects('makeDirectory') ->with('src/path/Models', 0755, true); $this->files->expects('put') - ->with('src/path/Models/Comment.php', $this->fixture('models/model-configured.php')); + ->with('src/path/Models/Comment.php', $this->fixture('models/model-configured-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/relationships.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -397,7 +397,7 @@ public function output_respects_configuration() /** * @test * @environment-setup useLaravel8 - * @dataProvider docBlockModelsDataProvider + * @dataProvider laravel8DocBlockModelsDataProvider */ public function output_generates_phpdoc_for_model($definition, $path, $model) { @@ -494,7 +494,7 @@ public function output_generates_phpdoc_for_model_l7($definition, $path, $model) ->andReturnTrue(); $this->files->expects('put') - ->with($path, $this->fixture(str_replace('models', 'models/no-factory', $model))); + ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); $tree = $this->blueprint->analyze($tokens); @@ -548,7 +548,7 @@ public function output_generates_phpdoc_for_model_l6($definition, $path, $model) ->andReturnTrue(); $this->files->expects('put') - ->with($path, $this->fixture(str_replace('models', 'models/no-factory', $model))); + ->with($path, $this->fixture(str_replace('models', 'models', $model))); $tokens = $this->blueprint->parse($this->fixture($definition)); $tree = $this->blueprint->analyze($tokens); @@ -585,7 +585,7 @@ public function output_generates_models_with_guarded_property_when_config_option ->andReturnTrue(); $this->files->expects('put') - ->with('app/Comment.php', $this->fixture('models/model-guarded.php')); + ->with('app/Comment.php', $this->fixture('models/model-guarded-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/model-guarded.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -601,7 +601,7 @@ public function output_generates_models_with_custom_namespace_correctly() { $definition = 'drafts/custom-models-namespace.yaml'; $path = 'app/Models/Tag.php'; - $model = 'models/custom-models-namespace.php'; + $model = 'models/custom-models-namespace-laravel8.php'; $this->app['config']->set('blueprint.models_namespace', 'Models'); @@ -656,7 +656,7 @@ public function output_generates_models_with_custom_pivot_columns() ->with('app') ->andReturnTrue(); $this->files->expects('put') - ->with('app/User.php', $this->fixture('models/custom-pivot-table-name.php')); + ->with('app/User.php', $this->fixture('models/custom-pivot-table-name-laravel8.php')); $tokens = $this->blueprint->parse($this->fixture('drafts/custom-pivot-table-name.yaml')); $tree = $this->blueprint->analyze($tokens); @@ -689,4 +689,30 @@ public function docBlockModelsDataProvider() ['drafts/foreign-key-shorthand.yaml', 'app/Comment.php', 'models/foreign-key-shorthand-phpdoc.php'], ]; } + + public function laravel8ModelTreeDataProvider() + { + return [ + ['drafts/readme-example.yaml', 'app/Post.php', 'models/readme-example-laravel8.php'], + ['drafts/with-timezones.yaml', 'app/Comment.php', 'models/comment-laravel8.php'], + ['drafts/soft-deletes.yaml', 'app/Comment.php', 'models/soft-deletes-laravel8.php'], + ['drafts/relationships.yaml', 'app/Comment.php', 'models/relationships-laravel8.php'], + ['drafts/unconventional.yaml', 'app/Team.php', 'models/unconventional-laravel8.php'], + ['drafts/nested-components.yaml', 'app/Admin/User.php', 'models/nested-components-laravel8.php'], + ['drafts/resource-statements.yaml', 'app/User.php', 'models/resource-statements-laravel8.php'], + ['drafts/all-column-types.yaml', 'app/AllType.php', 'models/all-column-types-laravel8.php'], + ['drafts/alias-relationships.yaml', 'app/Salesman.php', 'models/alias-relationships-laravel8.php'], + ]; + } + + public function laravel8DocBlockModelsDataProvider() + { + return [ + ['drafts/readme-example.yaml', 'app/Post.php', 'models/readme-example-phpdoc-laravel8.php'], + ['drafts/soft-deletes.yaml', 'app/Comment.php', 'models/soft-deletes-phpdoc-laravel8.php'], + ['drafts/relationships.yaml', 'app/Comment.php', 'models/relationships-phpdoc-laravel8.php'], + ['drafts/disable-auto-columns.yaml', 'app/State.php', 'models/disable-auto-columns-phpdoc-laravel8.php'], + ['drafts/foreign-key-shorthand.yaml', 'app/Comment.php', 'models/foreign-key-shorthand-phpdoc-laravel8.php'], + ]; + } } diff --git a/tests/fixtures/models/no-factory/alias-relationships.php b/tests/fixtures/models/alias-relationships-laravel8.php similarity index 90% rename from tests/fixtures/models/no-factory/alias-relationships.php rename to tests/fixtures/models/alias-relationships-laravel8.php index 2f810720..22ff46fc 100644 --- a/tests/fixtures/models/no-factory/alias-relationships.php +++ b/tests/fixtures/models/alias-relationships-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Salesman extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/alias-relationships.php b/tests/fixtures/models/alias-relationships.php index 22ff46fc..2f810720 100644 --- a/tests/fixtures/models/alias-relationships.php +++ b/tests/fixtures/models/alias-relationships.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Salesman extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/all-column-types.php b/tests/fixtures/models/all-column-types-laravel8.php similarity index 96% rename from tests/fixtures/models/no-factory/all-column-types.php rename to tests/fixtures/models/all-column-types-laravel8.php index bcefe7c7..7e935f53 100644 --- a/tests/fixtures/models/no-factory/all-column-types.php +++ b/tests/fixtures/models/all-column-types-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class AllType extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/all-column-types.php b/tests/fixtures/models/all-column-types.php index 7e935f53..bcefe7c7 100644 --- a/tests/fixtures/models/all-column-types.php +++ b/tests/fixtures/models/all-column-types.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class AllType extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/certificate-pascal-case-example.php b/tests/fixtures/models/certificate-pascal-case-example-laravel8.php similarity index 91% rename from tests/fixtures/models/no-factory/certificate-pascal-case-example.php rename to tests/fixtures/models/certificate-pascal-case-example-laravel8.php index 2807be48..e9e4668a 100644 --- a/tests/fixtures/models/no-factory/certificate-pascal-case-example.php +++ b/tests/fixtures/models/certificate-pascal-case-example-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Certificate extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/certificate-pascal-case-example.php b/tests/fixtures/models/certificate-pascal-case-example.php index e9e4668a..2807be48 100644 --- a/tests/fixtures/models/certificate-pascal-case-example.php +++ b/tests/fixtures/models/certificate-pascal-case-example.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Certificate extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/certificate-type-pascal-case-example.php b/tests/fixtures/models/certificate-type-pascal-case-example-laravel8.php similarity index 87% rename from tests/fixtures/models/no-factory/certificate-type-pascal-case-example.php rename to tests/fixtures/models/certificate-type-pascal-case-example-laravel8.php index 025b3aa4..febacb2c 100644 --- a/tests/fixtures/models/no-factory/certificate-type-pascal-case-example.php +++ b/tests/fixtures/models/certificate-type-pascal-case-example-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class CertificateType extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/certificate-type-pascal-case-example.php b/tests/fixtures/models/certificate-type-pascal-case-example.php index febacb2c..025b3aa4 100644 --- a/tests/fixtures/models/certificate-type-pascal-case-example.php +++ b/tests/fixtures/models/certificate-type-pascal-case-example.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class CertificateType extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/comment.php b/tests/fixtures/models/comment-laravel8.php similarity index 82% rename from tests/fixtures/models/no-factory/comment.php rename to tests/fixtures/models/comment-laravel8.php index 87fe82f4..b575d3db 100644 --- a/tests/fixtures/models/no-factory/comment.php +++ b/tests/fixtures/models/comment-laravel8.php @@ -2,12 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Comment extends Model { - use SoftDeletes; + use HasFactory, SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/comment.php b/tests/fixtures/models/comment.php index b575d3db..87fe82f4 100644 --- a/tests/fixtures/models/comment.php +++ b/tests/fixtures/models/comment.php @@ -2,13 +2,12 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Comment extends Model { - use HasFactory, SoftDeletes; + use SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/no-factory/custom-models-namespace.php b/tests/fixtures/models/custom-models-namespace-laravel8.php similarity index 85% rename from tests/fixtures/models/no-factory/custom-models-namespace.php rename to tests/fixtures/models/custom-models-namespace-laravel8.php index 7ecdad19..9746730d 100644 --- a/tests/fixtures/models/no-factory/custom-models-namespace.php +++ b/tests/fixtures/models/custom-models-namespace-laravel8.php @@ -2,12 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Tag extends Model { - use SoftDeletes; + use HasFactory, SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/custom-models-namespace.php b/tests/fixtures/models/custom-models-namespace.php index 9746730d..7ecdad19 100644 --- a/tests/fixtures/models/custom-models-namespace.php +++ b/tests/fixtures/models/custom-models-namespace.php @@ -2,13 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Tag extends Model { - use HasFactory, SoftDeletes; + use SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/no-factory/custom-pivot-table-name.php b/tests/fixtures/models/custom-pivot-table-name-laravel8.php similarity index 89% rename from tests/fixtures/models/no-factory/custom-pivot-table-name.php rename to tests/fixtures/models/custom-pivot-table-name-laravel8.php index 43a9a9e7..2203670c 100644 --- a/tests/fixtures/models/no-factory/custom-pivot-table-name.php +++ b/tests/fixtures/models/custom-pivot-table-name-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/custom-pivot-table-name.php b/tests/fixtures/models/custom-pivot-table-name.php index 2203670c..43a9a9e7 100644 --- a/tests/fixtures/models/custom-pivot-table-name.php +++ b/tests/fixtures/models/custom-pivot-table-name.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/disable-auto-columns.php b/tests/fixtures/models/disable-auto-columns-laravel8.php similarity index 88% rename from tests/fixtures/models/no-factory/disable-auto-columns.php rename to tests/fixtures/models/disable-auto-columns-laravel8.php index e5b4681c..72f5f28c 100644 --- a/tests/fixtures/models/no-factory/disable-auto-columns.php +++ b/tests/fixtures/models/disable-auto-columns-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class State extends Model { + use HasFactory; + /** * Indicates if the model should be timestamped. * diff --git a/tests/fixtures/models/no-factory/disable-auto-columns-phpdoc.php b/tests/fixtures/models/disable-auto-columns-phpdoc-laravel8.php similarity index 89% rename from tests/fixtures/models/no-factory/disable-auto-columns-phpdoc.php rename to tests/fixtures/models/disable-auto-columns-phpdoc-laravel8.php index a7f7750a..accd347f 100644 --- a/tests/fixtures/models/no-factory/disable-auto-columns-phpdoc.php +++ b/tests/fixtures/models/disable-auto-columns-phpdoc-laravel8.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -11,6 +12,8 @@ */ class State extends Model { + use HasFactory; + /** * Indicates if the model should be timestamped. * diff --git a/tests/fixtures/models/disable-auto-columns-phpdoc.php b/tests/fixtures/models/disable-auto-columns-phpdoc.php index accd347f..a7f7750a 100644 --- a/tests/fixtures/models/disable-auto-columns-phpdoc.php +++ b/tests/fixtures/models/disable-auto-columns-phpdoc.php @@ -2,7 +2,6 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -12,8 +11,6 @@ */ class State extends Model { - use HasFactory; - /** * Indicates if the model should be timestamped. * diff --git a/tests/fixtures/models/disable-auto-columns.php b/tests/fixtures/models/disable-auto-columns.php index 72f5f28c..e5b4681c 100644 --- a/tests/fixtures/models/disable-auto-columns.php +++ b/tests/fixtures/models/disable-auto-columns.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class State extends Model { - use HasFactory; - /** * Indicates if the model should be timestamped. * diff --git a/tests/fixtures/models/no-factory/foreign-key-shorthand-phpdoc.php b/tests/fixtures/models/foreign-key-shorthand-phpdoc-laravel8.php similarity index 94% rename from tests/fixtures/models/no-factory/foreign-key-shorthand-phpdoc.php rename to tests/fixtures/models/foreign-key-shorthand-phpdoc-laravel8.php index be2874c7..0a107d4a 100644 --- a/tests/fixtures/models/no-factory/foreign-key-shorthand-phpdoc.php +++ b/tests/fixtures/models/foreign-key-shorthand-phpdoc-laravel8.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -14,6 +15,8 @@ */ class Comment extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/foreign-key-shorthand-phpdoc.php b/tests/fixtures/models/foreign-key-shorthand-phpdoc.php index 0a107d4a..be2874c7 100644 --- a/tests/fixtures/models/foreign-key-shorthand-phpdoc.php +++ b/tests/fixtures/models/foreign-key-shorthand-phpdoc.php @@ -2,7 +2,6 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -15,8 +14,6 @@ */ class Comment extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/image-polymorphic-relationship.php b/tests/fixtures/models/image-polymorphic-relationship-laravel8.php similarity index 86% rename from tests/fixtures/models/no-factory/image-polymorphic-relationship.php rename to tests/fixtures/models/image-polymorphic-relationship-laravel8.php index 8aa3b034..47922960 100644 --- a/tests/fixtures/models/no-factory/image-polymorphic-relationship.php +++ b/tests/fixtures/models/image-polymorphic-relationship-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Image extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/image-polymorphic-relationship.php b/tests/fixtures/models/image-polymorphic-relationship.php index 47922960..8aa3b034 100644 --- a/tests/fixtures/models/image-polymorphic-relationship.php +++ b/tests/fixtures/models/image-polymorphic-relationship.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Image extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/model-configured.php b/tests/fixtures/models/model-configured-laravel8.php similarity index 90% rename from tests/fixtures/models/no-factory/model-configured.php rename to tests/fixtures/models/model-configured-laravel8.php index cc8d9f1d..0693b3b3 100644 --- a/tests/fixtures/models/no-factory/model-configured.php +++ b/tests/fixtures/models/model-configured-laravel8.php @@ -2,10 +2,13 @@ namespace Some\App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/model-configured.php b/tests/fixtures/models/model-configured.php index 0693b3b3..cc8d9f1d 100644 --- a/tests/fixtures/models/model-configured.php +++ b/tests/fixtures/models/model-configured.php @@ -2,13 +2,10 @@ namespace Some\App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/model-guarded.php b/tests/fixtures/models/model-guarded-laravel8.php similarity index 83% rename from tests/fixtures/models/no-factory/model-guarded.php rename to tests/fixtures/models/model-guarded-laravel8.php index 58a9d7b0..d95b1264 100644 --- a/tests/fixtures/models/no-factory/model-guarded.php +++ b/tests/fixtures/models/model-guarded-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { + use HasFactory; + /** * The attributes that aren't mass assignable. * diff --git a/tests/fixtures/models/model-guarded.php b/tests/fixtures/models/model-guarded.php index d95b1264..58a9d7b0 100644 --- a/tests/fixtures/models/model-guarded.php +++ b/tests/fixtures/models/model-guarded.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { - use HasFactory; - /** * The attributes that aren't mass assignable. * diff --git a/tests/fixtures/models/no-factory/model-relationships.php b/tests/fixtures/models/model-relationships-laravel8.php similarity index 92% rename from tests/fixtures/models/no-factory/model-relationships.php rename to tests/fixtures/models/model-relationships-laravel8.php index 9accc009..f75d93dd 100644 --- a/tests/fixtures/models/no-factory/model-relationships.php +++ b/tests/fixtures/models/model-relationships-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Subscription extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/model-relationships.php b/tests/fixtures/models/model-relationships.php index f75d93dd..9accc009 100644 --- a/tests/fixtures/models/model-relationships.php +++ b/tests/fixtures/models/model-relationships.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Subscription extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/nested-components.php b/tests/fixtures/models/nested-components-laravel8.php similarity index 88% rename from tests/fixtures/models/no-factory/nested-components.php rename to tests/fixtures/models/nested-components-laravel8.php index c9034556..32d7f64a 100644 --- a/tests/fixtures/models/no-factory/nested-components.php +++ b/tests/fixtures/models/nested-components-laravel8.php @@ -2,10 +2,13 @@ namespace App\Admin; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/nested-components.php b/tests/fixtures/models/nested-components.php index 32d7f64a..c9034556 100644 --- a/tests/fixtures/models/nested-components.php +++ b/tests/fixtures/models/nested-components.php @@ -2,13 +2,10 @@ namespace App\Admin; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/post-polymorphic-relationship.php b/tests/fixtures/models/post-polymorphic-relationship-laravel8.php similarity index 86% rename from tests/fixtures/models/no-factory/post-polymorphic-relationship.php rename to tests/fixtures/models/post-polymorphic-relationship-laravel8.php index a985d00d..6d9bce6a 100644 --- a/tests/fixtures/models/no-factory/post-polymorphic-relationship.php +++ b/tests/fixtures/models/post-polymorphic-relationship-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/post-polymorphic-relationship.php b/tests/fixtures/models/post-polymorphic-relationship.php index 6d9bce6a..a985d00d 100644 --- a/tests/fixtures/models/post-polymorphic-relationship.php +++ b/tests/fixtures/models/post-polymorphic-relationship.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/readme-example.php b/tests/fixtures/models/readme-example-laravel8.php similarity index 90% rename from tests/fixtures/models/no-factory/readme-example.php rename to tests/fixtures/models/readme-example-laravel8.php index 3e8bc307..2bc4e291 100644 --- a/tests/fixtures/models/no-factory/readme-example.php +++ b/tests/fixtures/models/readme-example-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/readme-example-phpdoc.php b/tests/fixtures/models/readme-example-phpdoc-laravel8.php similarity index 93% rename from tests/fixtures/models/no-factory/readme-example-phpdoc.php rename to tests/fixtures/models/readme-example-phpdoc-laravel8.php index d7889ea0..5dc2245f 100644 --- a/tests/fixtures/models/no-factory/readme-example-phpdoc.php +++ b/tests/fixtures/models/readme-example-phpdoc-laravel8.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -15,6 +16,8 @@ */ class Post extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/readme-example-phpdoc.php b/tests/fixtures/models/readme-example-phpdoc.php index 5dc2245f..d7889ea0 100644 --- a/tests/fixtures/models/readme-example-phpdoc.php +++ b/tests/fixtures/models/readme-example-phpdoc.php @@ -2,7 +2,6 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -16,8 +15,6 @@ */ class Post extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/readme-example.php b/tests/fixtures/models/readme-example.php index 2bc4e291..3e8bc307 100644 --- a/tests/fixtures/models/readme-example.php +++ b/tests/fixtures/models/readme-example.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/relationships.php b/tests/fixtures/models/relationships-laravel8.php similarity index 89% rename from tests/fixtures/models/no-factory/relationships.php rename to tests/fixtures/models/relationships-laravel8.php index fb791565..6f9ee16d 100644 --- a/tests/fixtures/models/no-factory/relationships.php +++ b/tests/fixtures/models/relationships-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/relationships-phpdoc.php b/tests/fixtures/models/relationships-phpdoc-laravel8.php similarity index 92% rename from tests/fixtures/models/no-factory/relationships-phpdoc.php rename to tests/fixtures/models/relationships-phpdoc-laravel8.php index 68b0cd87..479037cf 100644 --- a/tests/fixtures/models/no-factory/relationships-phpdoc.php +++ b/tests/fixtures/models/relationships-phpdoc-laravel8.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -13,6 +14,8 @@ */ class Comment extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/relationships-phpdoc.php b/tests/fixtures/models/relationships-phpdoc.php index 479037cf..68b0cd87 100644 --- a/tests/fixtures/models/relationships-phpdoc.php +++ b/tests/fixtures/models/relationships-phpdoc.php @@ -2,7 +2,6 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** @@ -14,8 +13,6 @@ */ class Comment extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/relationships.php b/tests/fixtures/models/relationships.php index 6f9ee16d..fb791565 100644 --- a/tests/fixtures/models/relationships.php +++ b/tests/fixtures/models/relationships.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Comment extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/resource-statements.php b/tests/fixtures/models/resource-statements-laravel8.php similarity index 88% rename from tests/fixtures/models/no-factory/resource-statements.php rename to tests/fixtures/models/resource-statements-laravel8.php index ff7aa920..8cd6f10c 100644 --- a/tests/fixtures/models/no-factory/resource-statements.php +++ b/tests/fixtures/models/resource-statements-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/resource-statements.php b/tests/fixtures/models/resource-statements.php index 8cd6f10c..ff7aa920 100644 --- a/tests/fixtures/models/resource-statements.php +++ b/tests/fixtures/models/resource-statements.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/soft-deletes.php b/tests/fixtures/models/soft-deletes-laravel8.php similarity index 86% rename from tests/fixtures/models/no-factory/soft-deletes.php rename to tests/fixtures/models/soft-deletes-laravel8.php index 1f3df1b9..ead0ced7 100644 --- a/tests/fixtures/models/no-factory/soft-deletes.php +++ b/tests/fixtures/models/soft-deletes-laravel8.php @@ -2,12 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Comment extends Model { - use SoftDeletes; + use HasFactory, SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/no-factory/soft-deletes-phpdoc.php b/tests/fixtures/models/soft-deletes-phpdoc-laravel8.php similarity index 90% rename from tests/fixtures/models/no-factory/soft-deletes-phpdoc.php rename to tests/fixtures/models/soft-deletes-phpdoc-laravel8.php index ca76e81e..fd77814c 100644 --- a/tests/fixtures/models/no-factory/soft-deletes-phpdoc.php +++ b/tests/fixtures/models/soft-deletes-phpdoc-laravel8.php @@ -2,6 +2,7 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,7 +15,7 @@ */ class Comment extends Model { - use SoftDeletes; + use HasFactory, SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/soft-deletes-phpdoc.php b/tests/fixtures/models/soft-deletes-phpdoc.php index fd77814c..ca76e81e 100644 --- a/tests/fixtures/models/soft-deletes-phpdoc.php +++ b/tests/fixtures/models/soft-deletes-phpdoc.php @@ -2,7 +2,6 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -15,7 +14,7 @@ */ class Comment extends Model { - use HasFactory, SoftDeletes; + use SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/soft-deletes.php b/tests/fixtures/models/soft-deletes.php index ead0ced7..1f3df1b9 100644 --- a/tests/fixtures/models/soft-deletes.php +++ b/tests/fixtures/models/soft-deletes.php @@ -2,13 +2,12 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Comment extends Model { - use HasFactory, SoftDeletes; + use SoftDeletes; /** * The attributes that are mass assignable. diff --git a/tests/fixtures/models/no-factory/unconventional.php b/tests/fixtures/models/unconventional-laravel8.php similarity index 90% rename from tests/fixtures/models/no-factory/unconventional.php rename to tests/fixtures/models/unconventional-laravel8.php index ed640e47..878b0821 100644 --- a/tests/fixtures/models/no-factory/unconventional.php +++ b/tests/fixtures/models/unconventional-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Team extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/unconventional.php b/tests/fixtures/models/unconventional.php index 878b0821..ed640e47 100644 --- a/tests/fixtures/models/unconventional.php +++ b/tests/fixtures/models/unconventional.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Team extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/no-factory/user-polymorphic-relationship.php b/tests/fixtures/models/user-polymorphic-relationship-laravel8.php similarity index 86% rename from tests/fixtures/models/no-factory/user-polymorphic-relationship.php rename to tests/fixtures/models/user-polymorphic-relationship-laravel8.php index dd5f75e4..7df81bc9 100644 --- a/tests/fixtures/models/no-factory/user-polymorphic-relationship.php +++ b/tests/fixtures/models/user-polymorphic-relationship-laravel8.php @@ -2,10 +2,13 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { + use HasFactory; + /** * The attributes that are mass assignable. * diff --git a/tests/fixtures/models/user-polymorphic-relationship.php b/tests/fixtures/models/user-polymorphic-relationship.php index 7df81bc9..dd5f75e4 100644 --- a/tests/fixtures/models/user-polymorphic-relationship.php +++ b/tests/fixtures/models/user-polymorphic-relationship.php @@ -2,13 +2,10 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class User extends Model { - use HasFactory; - /** * The attributes that are mass assignable. * From 38392239333f7dd1e2782cb38da019a7455717ba Mon Sep 17 00:00:00 2001 From: Nathan E Date: Thu, 10 Sep 2020 13:52:09 -0400 Subject: [PATCH 3/4] chore: rename isLaravel8Up to isLaravel8OrHigher --- src/Generators/FactoryGenerator.php | 30 ++++++++++++++--------------- src/Generators/ModelGenerator.php | 8 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 3919d13a..1d0c2e89 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -29,7 +29,7 @@ public function output(Tree $tree): array $output = []; - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $stub = $this->files->stub('factory.stub'); } else { $stub = $this->files->stub('factory.closure.stub'); @@ -37,7 +37,7 @@ public function output(Tree $tree): array /** @var \Blueprint\Models\Model $model */ foreach ($tree->models() as $model) { - if (! $this->isLaravel8Up()) { + if (! $this->isLaravel8OrHigher()) { $this->addImport($model, 'Faker\Generator as Faker'); } $this->addImport($model, $model->fullyQualifiedClassName()); @@ -75,7 +75,7 @@ protected function populateStub(string $stub, Model $model) { $stub = str_replace('{{ model }}', $model->name(), $stub); $stub = str_replace('//', $this->buildDefinition($model), $stub); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $stub = str_replace('use {{ namespacedModel }};', $this->buildImports($model), $stub); } else { $stub = str_replace('use Faker\Generator as Faker;'.PHP_EOL.'use {{ namespacedModel }};', $this->buildImports($model), $stub); @@ -121,11 +121,11 @@ protected function buildDefinition(Model $model) $class = Str::studly(Str::singular($table)); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $this->addImport($model, $model->fullyQualifiedNamespace().'\\'.$class); } if ($key === 'id') { - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()', $class); $definition .= ','.PHP_EOL; @@ -135,7 +135,7 @@ protected function buildDefinition(Model $model) $definition .= ','.PHP_EOL; } } else { - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()->create()->%s', $class, $key); $definition .= ','.PHP_EOL; @@ -151,7 +151,7 @@ protected function buildDefinition(Model $model) $name = Str::beforeLast($column->name(), '_id'); $class = Str::studly($column->attributes()[0] ?? $name); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $this->addImport($model, $model->fullyQualifiedNamespace().'\\'.$class); $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()', $class); @@ -162,7 +162,7 @@ protected function buildDefinition(Model $model) $definition .= ','.PHP_EOL; } elseif (in_array($column->dataType(), ['enum', 'set']) && ! empty($column->attributes())) { $faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType()); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= '$this->faker->'.$faker; } else { @@ -177,7 +177,7 @@ protected function buildDefinition(Model $model) ); } elseif (in_array($column->dataType(), ['decimal', 'double', 'float'])) { $faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType()); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= '$this->faker->'.$faker; } else { @@ -196,7 +196,7 @@ protected function buildDefinition(Model $model) ); } elseif (in_array($column->dataType(), ['json', 'jsonb'])) { $default = $column->defaultValue() ?? "'{}'"; - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => {$default},".PHP_EOL; } else { $definition .= str_repeat(self::INDENT, 2)."'{$column->name()}' => {$default},".PHP_EOL; @@ -205,7 +205,7 @@ protected function buildDefinition(Model $model) if ($column->isNullable()) { continue; } - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_id'", FakerRegistry::fakerDataType('id'), PHP_EOL); $definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL); } else { @@ -213,7 +213,7 @@ protected function buildDefinition(Model $model) $definition .= sprintf('%s%s => $faker->%s,%s', str_repeat(self::INDENT, 2), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL); } } elseif ($column->dataType() === 'rememberToken') { - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; } else { $this->addImport($model, 'Illuminate\Support\Str'); @@ -222,7 +222,7 @@ protected function buildDefinition(Model $model) $definition .= 'Str::random(10)'; $definition .= ','.PHP_EOL; } else { - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; } else { $definition .= str_repeat(self::INDENT, 2)."'{$column->name()}' => "; @@ -238,7 +238,7 @@ protected function buildDefinition(Model $model) $faker = 'word'; } - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $definition .= '$this->faker->'.$faker; } else { $definition .= '$faker->'.$faker; @@ -276,7 +276,7 @@ private function fillableColumns(array $columns): array }); } - protected function isLaravel8Up() + protected function isLaravel8OrHigher() { return version_compare(App::version(), '8.0.0', '>='); } diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index 8e0a9fd1..c19b91d4 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -24,7 +24,7 @@ public function output(Tree $tree): array { $output = []; - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $stub = $this->files->stub('model.class.stub'); } else { $stub = $this->files->stub('model.class.no-factory.stub'); @@ -53,7 +53,7 @@ public function types(): array protected function populateStub(string $stub, Model $model) { - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $stub = str_replace('{{ namespace }}', $model->fullyQualifiedNamespace(), $stub); $stub = str_replace(PHP_EOL.'class {{ class }}', $this->buildClassPhpDoc($model).PHP_EOL.'class {{ class }}', $stub); $stub = str_replace('{{ class }}', $model->name(), $stub); @@ -232,7 +232,7 @@ protected function addTraits(Model $model, $stub) } $stub = str_replace('use Illuminate\\Database\\Eloquent\\Model;', 'use Illuminate\\Database\\Eloquent\\Model;'.PHP_EOL.'use Illuminate\\Database\\Eloquent\\SoftDeletes;', $stub); - if ($this->isLaravel8Up()) { + if ($this->isLaravel8OrHigher()) { $stub = Str::replaceFirst('use HasFactory', 'use HasFactory, SoftDeletes', $stub); } else { $stub = Str::replaceFirst('{', '{'.PHP_EOL.' use SoftDeletes;'.PHP_EOL, $stub); @@ -307,7 +307,7 @@ private function castForColumn(Column $column) } } - protected function isLaravel8Up() + protected function isLaravel8OrHigher() { return version_compare(App::version(), '8.0.0', '>='); } From ceae5b847570b77b8d59888e78ca42dd1849fa28 Mon Sep 17 00:00:00 2001 From: Nathan E Date: Thu, 10 Sep 2020 14:18:18 -0400 Subject: [PATCH 4/4] refactor: remove code duplication --- src/Blueprint.php | 6 +++++ src/Generators/FactoryGenerator.php | 36 ++++++++++++----------------- src/Generators/ModelGenerator.php | 12 +++------- src/Generators/SeederGenerator.php | 15 ++++-------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/Blueprint.php b/src/Blueprint.php index c5383017..f0948ad1 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -4,6 +4,7 @@ use Blueprint\Contracts\Generator; use Blueprint\Contracts\Lexer; +use Illuminate\Support\Facades\App; use Illuminate\Support\Str; use Symfony\Component\Yaml\Yaml; @@ -29,6 +30,11 @@ public static function appPath() return str_replace('\\', '/', config('blueprint.app_path')); } + public static function isLaravel8OrHigher() + { + return version_compare(App::version(), '8.0.0', '>='); + } + public function parse($content, $strip_dashes = true) { $content = str_replace(["\r\n", "\r"], "\n", $content); diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 1d0c2e89..a0bbb02f 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -2,11 +2,11 @@ namespace Blueprint\Generators; +use Blueprint\Blueprint; use Blueprint\Contracts\Generator; use Blueprint\Models\Column; use Blueprint\Models\Model; use Blueprint\Tree; -use Illuminate\Support\Facades\App; use Illuminate\Support\Str; use Shift\Faker\Registry as FakerRegistry; @@ -28,8 +28,7 @@ public function output(Tree $tree): array { $output = []; - - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = $this->files->stub('factory.stub'); } else { $stub = $this->files->stub('factory.closure.stub'); @@ -37,7 +36,7 @@ public function output(Tree $tree): array /** @var \Blueprint\Models\Model $model */ foreach ($tree->models() as $model) { - if (! $this->isLaravel8OrHigher()) { + if (! Blueprint::isLaravel8OrHigher()) { $this->addImport($model, 'Faker\Generator as Faker'); } $this->addImport($model, $model->fullyQualifiedClassName()); @@ -75,7 +74,7 @@ protected function populateStub(string $stub, Model $model) { $stub = str_replace('{{ model }}', $model->name(), $stub); $stub = str_replace('//', $this->buildDefinition($model), $stub); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = str_replace('use {{ namespacedModel }};', $this->buildImports($model), $stub); } else { $stub = str_replace('use Faker\Generator as Faker;'.PHP_EOL.'use {{ namespacedModel }};', $this->buildImports($model), $stub); @@ -121,11 +120,11 @@ protected function buildDefinition(Model $model) $class = Str::studly(Str::singular($table)); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $this->addImport($model, $model->fullyQualifiedNamespace().'\\'.$class); } if ($key === 'id') { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()', $class); $definition .= ','.PHP_EOL; @@ -135,7 +134,7 @@ protected function buildDefinition(Model $model) $definition .= ','.PHP_EOL; } } else { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()->create()->%s', $class, $key); $definition .= ','.PHP_EOL; @@ -151,7 +150,7 @@ protected function buildDefinition(Model $model) $name = Str::beforeLast($column->name(), '_id'); $class = Str::studly($column->attributes()[0] ?? $name); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $this->addImport($model, $model->fullyQualifiedNamespace().'\\'.$class); $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= sprintf('%s::factory()', $class); @@ -162,7 +161,7 @@ protected function buildDefinition(Model $model) $definition .= ','.PHP_EOL; } elseif (in_array($column->dataType(), ['enum', 'set']) && ! empty($column->attributes())) { $faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType()); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= '$this->faker->'.$faker; } else { @@ -177,7 +176,7 @@ protected function buildDefinition(Model $model) ); } elseif (in_array($column->dataType(), ['decimal', 'double', 'float'])) { $faker = FakerRegistry::fakerData($column->name()) ?? FakerRegistry::fakerDataType($column->dataType()); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; $definition .= '$this->faker->'.$faker; } else { @@ -196,7 +195,7 @@ protected function buildDefinition(Model $model) ); } elseif (in_array($column->dataType(), ['json', 'jsonb'])) { $default = $column->defaultValue() ?? "'{}'"; - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => {$default},".PHP_EOL; } else { $definition .= str_repeat(self::INDENT, 2)."'{$column->name()}' => {$default},".PHP_EOL; @@ -205,7 +204,7 @@ protected function buildDefinition(Model $model) if ($column->isNullable()) { continue; } - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_id'", FakerRegistry::fakerDataType('id'), PHP_EOL); $definition .= sprintf('%s%s => $this->faker->%s,%s', str_repeat(self::INDENT, 3), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL); } else { @@ -213,7 +212,7 @@ protected function buildDefinition(Model $model) $definition .= sprintf('%s%s => $faker->%s,%s', str_repeat(self::INDENT, 2), "'{$column->name()}_type'", FakerRegistry::fakerDataType('string'), PHP_EOL); } } elseif ($column->dataType() === 'rememberToken') { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; } else { $this->addImport($model, 'Illuminate\Support\Str'); @@ -222,7 +221,7 @@ protected function buildDefinition(Model $model) $definition .= 'Str::random(10)'; $definition .= ','.PHP_EOL; } else { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= str_repeat(self::INDENT, 3)."'{$column->name()}' => "; } else { $definition .= str_repeat(self::INDENT, 2)."'{$column->name()}' => "; @@ -238,7 +237,7 @@ protected function buildDefinition(Model $model) $faker = 'word'; } - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $definition .= '$this->faker->'.$faker; } else { $definition .= '$faker->'.$faker; @@ -275,9 +274,4 @@ private function fillableColumns(array $columns): array return ! in_array('nullable', $column->modifiers()); }); } - - protected function isLaravel8OrHigher() - { - return version_compare(App::version(), '8.0.0', '>='); - } } diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index c19b91d4..335bda3d 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -7,7 +7,6 @@ use Blueprint\Models\Column; use Blueprint\Models\Model; use Blueprint\Tree; -use Illuminate\Support\Facades\App; use Illuminate\Support\Str; class ModelGenerator implements Generator @@ -24,7 +23,7 @@ public function output(Tree $tree): array { $output = []; - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = $this->files->stub('model.class.stub'); } else { $stub = $this->files->stub('model.class.no-factory.stub'); @@ -53,7 +52,7 @@ public function types(): array protected function populateStub(string $stub, Model $model) { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = str_replace('{{ namespace }}', $model->fullyQualifiedNamespace(), $stub); $stub = str_replace(PHP_EOL.'class {{ class }}', $this->buildClassPhpDoc($model).PHP_EOL.'class {{ class }}', $stub); $stub = str_replace('{{ class }}', $model->name(), $stub); @@ -232,7 +231,7 @@ protected function addTraits(Model $model, $stub) } $stub = str_replace('use Illuminate\\Database\\Eloquent\\Model;', 'use Illuminate\\Database\\Eloquent\\Model;'.PHP_EOL.'use Illuminate\\Database\\Eloquent\\SoftDeletes;', $stub); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = Str::replaceFirst('use HasFactory', 'use HasFactory, SoftDeletes', $stub); } else { $stub = Str::replaceFirst('{', '{'.PHP_EOL.' use SoftDeletes;'.PHP_EOL, $stub); @@ -307,11 +306,6 @@ private function castForColumn(Column $column) } } - protected function isLaravel8OrHigher() - { - return version_compare(App::version(), '8.0.0', '>='); - } - private function pretty_print_array(array $data, $assoc = true) { $output = var_export($data, true); diff --git a/src/Generators/SeederGenerator.php b/src/Generators/SeederGenerator.php index 27198fbc..ea61aedb 100644 --- a/src/Generators/SeederGenerator.php +++ b/src/Generators/SeederGenerator.php @@ -2,9 +2,9 @@ namespace Blueprint\Generators; +use Blueprint\Blueprint; use Blueprint\Contracts\Generator; use Blueprint\Tree; -use Illuminate\Support\Facades\App; class SeederGenerator implements Generator { @@ -31,7 +31,7 @@ public function output(Tree $tree): array $output = []; - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $stub = $this->files->stub('seeder.stub'); } else { $stub = $this->files->stub('seeder.no-factory.stub'); @@ -55,7 +55,7 @@ public function types(): array protected function populateStub(string $stub, string $model) { $stub = str_replace('{{ class }}', $this->getClassName($model), $stub); - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $this->addImport($model, 'Illuminate\Database\Seeder'); $stub = str_replace('//', $this->build($model), $stub); @@ -73,7 +73,7 @@ protected function getClassName(string $model) protected function build(string $model) { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { $this->addImport($model, $this->tree->fqcnForContext($model)); return sprintf('%s::factory()->times(5)->create();', class_basename($this->tree->fqcnForContext($model))); } @@ -97,15 +97,10 @@ private function addImport(string $model, $class) private function getPath($model) { - if ($this->isLaravel8OrHigher()) { + if (Blueprint::isLaravel8OrHigher()) { return 'database/seeders/'.$model.'Seeder.php'; } return 'database/seeds/'.$model.'Seeder.php'; } - - protected function isLaravel8OrHigher() - { - return version_compare(App::version(), '8.0.0', '>='); - } }