Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wadakatu/laravel-factory-refactor
Refactor the style of factory call from helper to static in Laravel 8.x, 9.x, 10.x.
https://github.com/wadakatu/laravel-factory-refactor
factory laravel php7 php8 refactor
Last synced: 24 days ago
JSON representation
Refactor the style of factory call from helper to static in Laravel 8.x, 9.x, 10.x.
- Host: GitHub
- URL: https://github.com/wadakatu/laravel-factory-refactor
- Owner: wadakatu
- License: mit
- Created: 2022-01-26T15:11:42.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-24T05:05:42.000Z (over 1 year ago)
- Last Synced: 2024-10-01T18:10:07.336Z (about 1 month ago)
- Topics: factory, laravel, php7, php8, refactor
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel-Factory-Refactor
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/wadakatu/laravel-factory-refactor?label=packagist)](https://packagist.org/packages/wadakatu/laravel-factory-refactor)
[![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/wadakatu/laravel-factory-refactor)](https://packagist.org/packages/wadakatu/laravel-factory-refactor)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/wadakatu/laravel-factory-refactor/blob/main/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:
```bash
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:
```bash
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.
```bash
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.
```bash
php artisan refactor:factory --dir app/Models --namespace App\\Models
```---
## Example
### Before
```phpt
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
```phpt
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](LICENSE.md) for more information.