├── LICENSE ├── README.md ├── builds └── shift-cli ├── composer.json └── config └── defaults.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Laravel Shift 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
6 | 7 | _This project has been archived and is no longer actively developed. All of its tasks are freely available to run using the [Shift Workbench](https://laravelshift.com/workbench)._ 8 | 9 | # Shift CLI 10 | A tool by [Shift](https://laravelshift.com/) to run automated tasks for refactoring and modernizing your Laravel projects. 11 | 12 | 13 | ## Installation 14 | The Shift CLI is bundled as a PHAR, so it has no dependencies and can be installed without conflicts. To use the Shift CLI in your Laravel project, you may install it locally by running: 15 | 16 | ```sh 17 | composer require --dev laravel-shift/cli 18 | ``` 19 | 20 | To easily use the Shift CLI for all your Laravel projects, you may install it globally by running: 21 | 22 | ```sh 23 | composer global require laravel-shift/cli 24 | ``` 25 | 26 | 27 | ## Basic Usage 28 | The recommended way to use the Shift CLI is to simply run the `shift-cli` command from the root of your Laravel project. This will run the default set of [automated tasks](#automated-tasks). The default tasks are based on conventions found in the latest version of Laravel and its documented examples. 29 | 30 | To run an individual task, or multiple tasks, you may pass them by name to the `run` command. For example, to run the `anonymous-migrations` and `facades-aliases` tasks, you may run: 31 | 32 | ```sh 33 | shift-cli run anonymous-migrations facade-aliases 34 | ``` 35 | 36 | By default, the automation is run against all PHP files under your current path. To limit the automation to a path or file, you may set the `--path` option. For example, to run the `anonymous-migrations` task against only the `database/migrations` directory, you may run: 37 | 38 | ```sh 39 | shift-cli run --path=database/migrations anonymous-migrations 40 | ``` 41 | 42 | You may also use the `--dirty` option to only run the automation against files which have changed since your last commit. For example, to run the `anonymous-migrations` task against only the uncommitted PHP files, you may run: 43 | 44 | ```sh 45 | shift-cli run --dirty anonymous-migrations 46 | ``` 47 | 48 | 49 | ## Automated Tasks 50 | To see a list of all available tasks, you may run: `shift-cli --tasks` 51 | 52 | Below is a list of the free tasks included with this package: 53 | 54 | - **anonymous-migrations**: (default) Convert class based database migrations into anonymous classes. 55 | - **check-lint**: Check PHP files for syntax errors. 56 | - **class-strings**: (default) Convert strings which contain class references to actual references using `::class`. 57 | - **debug-calls**: Remove calls to debugging functions (`var_dump`, `print_r`, `dd`, etc) from code. 58 | - **declare-strict**: Ensure PHP files declare `strict_types=1`. 59 | - **down-migration**: Remove the `down` method from migrations. 60 | - **explicit-orderby**: (default) Ensure queries use the `orderBy` and `orderByDesc` methods, instead of string arguments. 61 | - **facade-aliases**: (default) Ensure references to Laravel facades are fully qualified, instead of global aliases. 62 | - **faker-methods**: (default) Convert Faker data to method calls, instead of the deprecated property access. 63 | - **laravel-carbon**: Convert references to `Carbon\Carbon` to use the `Illuminate\Support\Carbon` wrapper. 64 | - **latest-oldest**: Ensure queries use `lastest` and `oldest` methods, instead of longhand `orderBy` methods. 65 | - **model-table**: (default) Remove the `table` property from models which follow Laravel conventions. 66 | - **order-model**: Order model classes by visibility and method type. 67 | - **remove-docblocks**: Remove PHP DocBlocks from code. 68 | - **rules-arrays**: (default) Ensure form request rules are defined as arrays, instead of strings. 69 | 70 | 71 | ## Advanced Usage 72 | The Shift CLI is meant to be integrated into your development workflow. Its focus is refactoring your code and ensuring consistency across your projects. As such, it pairs well with a code formatter. Shift recommends using [Laravel Pint](https://laravel.com/docs/pint) as it is a first-party package which applies the Laravel code style by default. It also uses [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) underneath, so you may easily configure it with all the same options. You may, of course, use PHP CS Fixer directly, or another code formatter like [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). 73 | 74 | For example, to run the Shift CLI and Pint together, you may run: 75 | 76 | ```sh 77 | shift-cli && pint 78 | ``` 79 | 80 | Taking this farther, you may automate this by setting up your own Composer script. For example, to run the Shift CLI and Pint together, you may add the following to your `composer.json` file: 81 | 82 | ```json 83 | { 84 | "scripts": { 85 | "lint": [ 86 | "shift-cli", 87 | "pint" 88 | ] 89 | } 90 | } 91 | ``` 92 | 93 | You may optimize this script by passing the `--dirty` option to both the Shift CLI and Pint. Once you have added this script, you may run: `composer lint` 94 | 95 | Additionally, you may add the `shift-cli` command to a pre-commit hook to ensure the automation is always run before making a commit. 96 | 97 | Finally, you are encouraged to add the `shift-cli` to your CI workflows. For example, you may run the `shift-cli` as part of every Pull Request to ensure all merged code consistently follows Laravel conventions. 98 | 99 | Examples of setting up Composer scripts and pre-commit hooks may be found in the [Shift CreatorSeries on Laracasts](https://laracasts.com/series/automated-laravel-upgrades/episodes/4). 100 | 101 | 102 | ## Additional Commands 103 | The Shift CLI comes with two additional commands: `publish` and `discover`. 104 | 105 | The `publish` command generates a Shift CLI configuration file - `shift-cli.json`. The generated configuration file includes all of the defaults. You may customize the configuration file to specify which tasks to run by default, additional paths to ignore, and options for individual tasks. 106 | 107 | The `discover` command regenerates the Shift CLI task manifest. This is done automatically anytime the Shift CLI is updated. However, you may need to run this command if you have included other packages which provide Shift CLI tasks. 108 | 109 | 110 | ## Support Policy 111 | The automated tasks within the Shift CLI prioritize the latest stable version of Laravel (currently Laravel 10). While there will be a grace period when new versions of Laravel are released, you are encouraged to keep your application upgraded (try using [Shift](https://laravelshift.com)). 112 | 113 | 114 | ## Contributing 115 | Contributions are welcome in the form of opening an issue or submitting a pull request. For issues to be considered, they should follow one of the templates. For PRs to be considered, they should have tests and all checks should pass. 116 | -------------------------------------------------------------------------------- /builds/shift-cli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laravel-shift/cli/f16ad8334fb885f7e343968dbd6f0a964c29defe/builds/shift-cli -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-shift/cli", 3 | "description": "A CLI tool for running automated tasks from Shift", 4 | "keywords": ["laravel", "php", "code", "refactor", "automation", "cli"], 5 | "license": "MIT", 6 | "abandoned": true, 7 | "require": { 8 | "php": "^8.1" 9 | }, 10 | "autoload": { 11 | "psr-4": { 12 | "Shift\\Cli\\": "src/" 13 | } 14 | }, 15 | "config": { 16 | "preferred-install": "dist", 17 | "sort-packages": true, 18 | "optimize-autoloader": true 19 | }, 20 | "minimum-stability": "dev", 21 | "prefer-stable": true, 22 | "bin": ["builds/shift-cli"] 23 | } 24 | -------------------------------------------------------------------------------- /config/defaults.php: -------------------------------------------------------------------------------- 1 | [ 5 | \Shift\Cli\Tasks\AnonymousMigrations::class, 6 | \Shift\Cli\Tasks\CheckLint::class, 7 | \Shift\Cli\Tasks\ClassStrings::class, 8 | \Shift\Cli\Tasks\DebugCalls::class, 9 | \Shift\Cli\Tasks\DeclareStrictTypes::class, 10 | \Shift\Cli\Tasks\DownMigration::class, 11 | \Shift\Cli\Tasks\ExplicitOrderBy::class, 12 | \Shift\Cli\Tasks\FacadeAliases::class, 13 | \Shift\Cli\Tasks\FakerMethods::class, 14 | \Shift\Cli\Tasks\LaravelCarbon::class, 15 | \Shift\Cli\Tasks\LatestOldest::class, 16 | \Shift\Cli\Tasks\ModelTableName::class, 17 | \Shift\Cli\Tasks\OrderModel::class, 18 | \Shift\Cli\Tasks\RemoveDocBlocks::class, 19 | \Shift\Cli\Tasks\RulesArrays::class, 20 | ], 21 | 22 | 'run' => [ 23 | 'anonymous-migrations', 24 | 'class-strings', 25 | 'explicit-orderby', 26 | 'facade-aliases', 27 | 'faker-methods', 28 | 'model-table', 29 | 'rules-arrays', 30 | ], 31 | 32 | ]; 33 | --------------------------------------------------------------------------------