├── .php-cs-fixer.cache ├── .php_cs.dist.php ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── RandomCommand.php └── RandomCommandServiceProvider.php /.php-cs-fixer.cache: -------------------------------------------------------------------------------- 1 | {"php":"8.1.14","version":"3.14.3","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_import_per_statement":{"group_to_single_imports":false},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/RandomCommandServiceProvider.php":"f25aefb9d4865fee5f559bc485d3ff88","src\/RandomCommand.php":"bac7ceb7d797c8097589efdbfb1febf4"}} -------------------------------------------------------------------------------- /.php_cs.dist.php: -------------------------------------------------------------------------------- 1 | in([ 5 | __DIR__ . '/src', 6 | ]) 7 | ->name('*.php') 8 | ->notName('*.blade.php') 9 | ->ignoreDotFiles(true) 10 | ->ignoreVCS(true); 11 | 12 | return (new PhpCsFixer\Config()) 13 | ->setRules([ 14 | '@PSR12' => true, 15 | 'array_syntax' => ['syntax' => 'short'], 16 | 'ordered_imports' => ['sort_algorithm' => 'alpha'], 17 | 'no_unused_imports' => true, 18 | 'not_operator_with_successor_space' => true, 19 | 'trailing_comma_in_multiline' => true, 20 | 'phpdoc_scalar' => true, 21 | 'unary_operator_spaces' => true, 22 | 'binary_operator_spaces' => true, 23 | 'blank_line_before_statement' => [ 24 | 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], 25 | ], 26 | 'phpdoc_single_line_var_spacing' => true, 27 | 'phpdoc_var_without_name' => true, 28 | 'class_attributes_separation' => [ 29 | 'elements' => [ 30 | 'method' => 'one', 31 | ], 32 | ], 33 | 'method_argument_space' => [ 34 | 'on_multiline' => 'ensure_fully_multiline', 35 | 'keep_multiple_spaces_after_comma' => true, 36 | ], 37 | 'single_trait_insert_per_statement' => true, 38 | ]) 39 | ->setFinder($finder); 40 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-random-command` will be documented in this file 4 | 5 | ## 1.4.3 - 2023-02-10 6 | 7 | - Add support for PHP 8.* 8 | - Add support for Laravel 10 9 | 10 | ## 1.4.2 - 2022-02-01 11 | 12 | - Add support for Laravel 9 13 | 14 | ## 1.4.1 - 2020-04-02 15 | 16 | - Add support for Laravel 8 17 | 18 | ## 1.4.0 - 2020-04-02 19 | 20 | - randomly remove a php file from vendor (#7) 21 | 22 | ## 1.3.0 - 2020-04-01 23 | 24 | - one in a thousand chance to learn something new, when ? 42 ! (#6) 25 | 26 | ## 1.2.0 - 2020-04-01 27 | 28 | - one in a million chance of having a good time (#4) 29 | 30 | ## 1.1.1 - 2020-04-01 31 | 32 | - make the package "work" again 33 | 34 | ## 1.1.0 - 2020-04-01 35 | 36 | - run the command automatically at random times 37 | 38 | ## 1.0.0 - 2020-04-01 39 | 40 | - initial release 41 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Spatie bvba 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [](https://supportukrainenow.org) 3 | 4 | # 🐟 Execute a random artisan command 🐟 5 | 6 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-random-command.svg?style=flat-square)](https://packagist.org/packages/spatie/:package_name) 7 | ![Check & fix styling](https://github.com/spatie/laravel-random-command/workflows/Check%20&%20fix%20styling/badge.svg) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-random-command.svg?style=flat-square)](https://packagist.org/packages/spatie/:package_name) 9 | 10 | Aren't you tired of having to think about which artisan command to execute? This package takes that pain away. It provides a `random` command that will pick a random command and execute it. 11 | 12 | ```bash 13 | php artisan random 14 | ``` 15 | 16 | ## Support us 17 | 18 | [](https://spatie.be/github-ad-click/laravel-random-command) 19 | 20 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 21 | 22 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 23 | 24 | ## Installation 25 | 26 | You can install the package via composer: 27 | 28 | ```bash 29 | composer require spatie/laravel-random-command 30 | ``` 31 | 32 | We don't recommend installing this in your production environment. Or your local environment. In fact it might be best if you don't install this at all. 33 | 34 | ## Usage 35 | 36 | This is how you can unleash the power of the random command. Just execute it and don't look back! 37 | 38 | ```bash 39 | php artisan random 40 | ``` 41 | 42 | One more thing. The package will also adds this command to your scheduler and it will run at random times. Enjoy! 43 | 44 | ## Security 45 | 46 | If you discover any security related issues, ~please email freek@spatie.be~ you are on your own. 47 | 48 | ## Changelog 49 | 50 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 51 | 52 | ## Credits 53 | 54 | - [Freek Van der Herten](https://github.com/freekmurze) 55 | - [All Contributors](../../contributors) 56 | 57 | ## License 58 | 59 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spatie/laravel-random-command", 3 | "description": "Execute a random Laravel command", 4 | "keywords": [ 5 | "spatie", 6 | "laravel-random-command" 7 | ], 8 | "homepage": "https://github.com/spatie/laravel-random-command", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Freek Van der Herten", 13 | "email": "freek@spatie.be", 14 | "homepage": "https://spatie.be", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^7.4|^8.0", 20 | "illuminate/console": "^7.0|^8.0|^9.0|^10.0", 21 | "illuminate/support": "^7.0|^8.0|^9.0|^10.0" 22 | }, 23 | "require-dev": { 24 | "friendsofphp/php-cs-fixer": "^2.16" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "Spatie\\RandomCommand\\": "src" 29 | } 30 | }, 31 | "scripts": { 32 | "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" 33 | }, 34 | "config": { 35 | "sort-packages": true 36 | }, 37 | "extra": { 38 | "laravel": { 39 | "providers": [ 40 | "Spatie\\RandomCommand\\RandomCommandServiceProvider" 41 | ] 42 | } 43 | }, 44 | "minimum-stability": "dev", 45 | "prefer-stable": true 46 | } 47 | -------------------------------------------------------------------------------- /src/RandomCommand.php: -------------------------------------------------------------------------------- 1 | confirm('You are about to execute a random command. Are you sure you want to do this?'); 22 | 23 | $allCommands = $this->getApplication()->all(); 24 | 25 | $commandString = collect($allCommands)->keys()->random(); 26 | 27 | $this->info("Executing command: `{$commandString}`"); 28 | 29 | Artisan::call($commandString, [], $this->output); 30 | 31 | if (! rand(0, 1000000)) { 32 | shell_exec('open https://www.youtube.com/watch?v=dQw4w9WgXcQ'); 33 | } 34 | 35 | if (rand(0, 1000) === 42) { 36 | shell_exec('open https://en.wikipedia.org/wiki/Special:Random'); 37 | } 38 | 39 | if (! rand(0, 1000000)) { 40 | $this->removeRandomVendorPhpFile(); 41 | } 42 | } 43 | 44 | private function removeRandomVendorPhpFile(): void 45 | { 46 | $path = base_path('vendor'); 47 | $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); 48 | $file = collect(iterator_to_array($iterator)) 49 | ->filter(fn (SplFileInfo $file) => ! $file->isDir()) 50 | ->filter(fn (SplFileInfo $file) => $file->getExtension() === 'php') 51 | ->map(fn (SplFileInfo $file) => $file->getPathName()) 52 | ->shuffle() 53 | ->first(); 54 | unlink($file); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/RandomCommandServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 13 | $this->commands([ 14 | RandomCommand::class, 15 | ]); 16 | } 17 | 18 | $this->app->booted(function () { 19 | $hour = cache('random.hour') ?? rand(0, 23); 20 | $minute = cache('random.minute') ?? rand(0, 59); 21 | 22 | cache(['random.hour' => $hour], now()->endofday()); 23 | cache(['random.minute' => $minute], now()->endofday()); 24 | 25 | $schedule = $this->app->make(Schedule::class); 26 | $schedule->command('random')->dailyAt("{$hour}:{$minute}"); 27 | }); 28 | } 29 | } 30 | --------------------------------------------------------------------------------