├── .gitignore ├── LICENSE ├── README.md ├── composer.json └── src ├── Commands └── CheckRoutes.php └── ServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | composer.lock 3 | .phpunit.result.cache 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 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 | **Archived** 2 | 3 | This project has been archived as its features have been superseded by the [Shift Workbench](https://laravelshift.com/workbench/). 4 | 5 | --- 6 | 7 | 8 | # Shift - Console 9 | A set of useful `artisan` commands to keep your Laravel applications fresh. 10 | 11 | ## Installation 12 | You can install the Shift Console via composer using the following command: 13 | 14 | ```sh 15 | composer require --dev laravel-shift/console 16 | ``` 17 | 18 | Shift Console will automatically register itself using [package discovery](https://laravel.com/docs/packages#package-discovery). 19 | 20 | ## Requirements 21 | Shift Console requires a Laravel application running version 6.0 or higher. **Not running the latest version?** [Run Shift](https://laravelshift.com/shifts). 22 | 23 | ## Basic Usage 24 | Currently, the Shift Console includes set `artisan` commands under the `shift` namespace. Currently, there is only one command - `shift:check-routes`. 25 | 26 | ```sh 27 | php artisan shift:check-routes 28 | ``` 29 | 30 | This command checks for _Dead Routes_ by reviewing your application routes for references to undefined controllers, methods, or invalid visibility. 31 | 32 | ## Contributing 33 | Contributions may be made by submitting a Pull Request against the `master` branch. Any submissions should be complete with tests and adhere to the [PSR-2 code style](https://www.php-fig.org/psr/psr-2/). 34 | 35 | You may also contribute by [opening an issue](https://github.com/laravel-shift/console/issues) to report a bug or suggest a new feature. 36 | 37 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-shift/console", 3 | "type": "library", 4 | "description": "A set of commands to keep your Laravel applications fresh.", 5 | "keywords": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "illuminate/console": "^6.0|^7.0|^8.0", 12 | "illuminate/support": "^6.0|^7.0|^8.0" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "Shift\\": "src/" 17 | } 18 | }, 19 | "extra": { 20 | "laravel": { 21 | "providers": [ 22 | "Shift\\ServiceProvider" 23 | ] 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Commands/CheckRoutes.php: -------------------------------------------------------------------------------- 1 | filter(function (Route $route) { 48 | return is_string($route->getAction('uses')); 49 | }) 50 | ->map(function (Route $route) { 51 | try { 52 | $controller = $route->getController(); 53 | $method = Str::parseCallback($route->getAction('uses'), '__invoke')[1]; 54 | 55 | if (is_null($method)) { 56 | return [ 57 | 'type' => 'undefined', 58 | 'action' => $route->getActionName() 59 | ]; 60 | } 61 | 62 | $reflectedMethod = new ReflectionMethod($controller, $method); 63 | if ($reflectedMethod->isPublic()) { 64 | return null; 65 | } 66 | 67 | return [ 68 | 'type' => 'visibility', 69 | 'action' => $route->getActionName() 70 | ]; 71 | } catch (BindingResolutionException $exception) { 72 | return [ 73 | 'type' => 'controller', 74 | 'action' => $route->getActionName() 75 | ]; 76 | } catch (ReflectionException $exception) { 77 | return [ 78 | 'type' => 'method', 79 | 'action' => $route->getActionName() 80 | ]; 81 | } 82 | }) 83 | ->filter() 84 | ->mapToGroups(function ($error) { 85 | return [$error['type'] => $error['action']]; 86 | }) 87 | ->sortBy('type') 88 | ->each(function ($actions, $type) { 89 | $this->displayHeader($type); 90 | $this->displayIssues($actions); 91 | }); 92 | } 93 | 94 | private function displayHeader($type) 95 | { 96 | if ($type === 'controller') { 97 | $this->output->error('Undefined Controllers'); 98 | $this->output->text([ 99 | 'The following actions referenced controllers which do not exist. To resolve, quickly create these controllers using `artisan make:controller` or remove these routes.' 100 | ]); 101 | } elseif ($type === 'method') { 102 | $this->output->warning('Undefined Methods'); 103 | $this->output->text([ 104 | 'The following actions referenced a method in the controller which did not exist. To resolve, you may add the method to the controller or remove these routes.' 105 | ]); 106 | } else { 107 | $this->output->note('Incorrect Visibility'); 108 | $this->output->text([ 109 | 'The following actions referenced methods which existed, but have the incorrect visibility. To resolve, you may update the method visibility to `public` or remove these routes.' 110 | ]); 111 | } 112 | 113 | $this->output->newLine(); 114 | } 115 | 116 | private function displayIssues(Collection $actions) 117 | { 118 | $this->output->listing($actions->toArray()); 119 | $this->output->newLine(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 27 | $this->commands([ 28 | \Shift\Commands\CheckRoutes::class, 29 | ]); 30 | } 31 | } 32 | 33 | /** 34 | * Get the services provided by the provider. 35 | * 36 | * @return array 37 | */ 38 | public function provides() 39 | { 40 | return [ 41 | \Shift\Commands\CheckRoutes::class, 42 | ]; 43 | } 44 | } 45 | --------------------------------------------------------------------------------