wadakatu/laravel-factory-refactor

Refactor the style of factory call from helper to static method for Laravel 8.x.

v2.1.0 2023-05-24 05:02 UTC

This package is auto-updated.

Last update: 2024-05-24 07:25:22 UTC


README

GitHub release (latest by date) Packagist PHP Version Support License

This package will help you to refactor the style of factory call from helper to static method for Laravel 8.x, 9.x, 10.x.

With this package, you can save plenty of time and focus on other important things.

Installation

You can install the package via composer:

composer require wadakatu/laravel-factory-refactor --dev

How to Use

To refactor the style of factory call from helper to static method, run the artisan command:

php artisan refactor:factory

Options

By default, all factory call under tests/ directory are the target of refactoring.

If you want to change the target directory, you can do that by using the --dir option.

php artisan refactor:factory --dir tests/Feature

By default, Tests\\ namespace is the target of refactoring.

If you want to change the target namespace, you can do that by using the --namespace option.

php artisan refactor:factory --dir app/Models --namespace App\\Models

Example

Before

        factory(User::class)->make();
        factory(App\Models\User::class)->make();
        factory(User::class, 10)->make();
        factory(App\Models\User::class, 10)->make();
        factory($model)->make();
        factory(User::class, $count['user'])->make();

After

        User::factory()->make();
        App\Models\User::factory()->make();
        User::factory()->count(10)->make();
        App\Models\User::factory()->count(10)->make();
        $model::factory()->make();
        User::factory()->count($count['user'])->make();

License

The MIT License (MIT). Please see license file for more information.