itstructure /
laravel-media-file-uploader
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Itstructure\MFU\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Symfony\Component\Process\Process; |
||
| 7 | use Itstructure\MFU\UploadServiceProvider; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class PublishCommand |
||
| 11 | * @package Itstructure\MFU\Commands |
||
| 12 | * @author Andrey Girnik <[email protected]> |
||
| 13 | */ |
||
| 14 | class PublishCommand extends Command |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The name and signature of the console command. |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $signature = 'uploader:publish ' . |
||
| 21 | '{--force : Overwrite existing files by default.}' . |
||
| 22 | '{--only= : Publish only specific part. Available parts: assets, config, views, lang, migrations.}'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The console command description. |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $description = 'Publish the Uploader package parts.'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Execute the console command. |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public function handle() |
||
| 35 | { |
||
| 36 | $this->info('Starting publication process of Uploader package parts...'); |
||
| 37 | |||
| 38 | $callArguments = ['--provider' => UploadServiceProvider::class]; |
||
| 39 | |||
| 40 | $dumpAutoload = false; |
||
| 41 | |||
| 42 | if ($this->option('only')) { |
||
| 43 | switch ($this->option('only')) { |
||
| 44 | case 'assets': |
||
| 45 | $this->info('Publish just a part: assets.'); |
||
| 46 | $callArguments['--tag'] = 'assets'; |
||
| 47 | break; |
||
| 48 | |||
| 49 | case 'config': |
||
| 50 | $this->info('Publish just a part: config.'); |
||
| 51 | $callArguments['--tag'] = 'config'; |
||
| 52 | break; |
||
| 53 | |||
| 54 | case 'views': |
||
| 55 | $this->info('Publish just a part: views.'); |
||
| 56 | $callArguments['--tag'] = 'views'; |
||
| 57 | break; |
||
| 58 | |||
| 59 | case 'lang': |
||
| 60 | $this->info('Publish just a part: lang.'); |
||
| 61 | $callArguments['--tag'] = 'lang'; |
||
| 62 | break; |
||
| 63 | |||
| 64 | case 'migrations': |
||
| 65 | $this->info('Publish just a part: migrations.'); |
||
| 66 | $callArguments['--tag'] = 'migrations'; |
||
| 67 | $dumpAutoload = true; |
||
| 68 | break; |
||
| 69 | |||
| 70 | default: |
||
| 71 | $this->error('Invalid "only" argument value!'); |
||
| 72 | return; |
||
| 73 | break; |
||
|
0 ignored issues
–
show
|
|||
| 74 | } |
||
| 75 | |||
| 76 | } else { |
||
| 77 | $this->info('Publish all parts: assets, config, views, lang, migrations.'); |
||
| 78 | $dumpAutoload = true; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($this->option('force')) { |
||
| 82 | $this->warn('Force publishing.'); |
||
| 83 | $callArguments['--force'] = true; |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->call('vendor:publish', $callArguments); |
||
| 87 | |||
| 88 | if ($dumpAutoload) { |
||
| 89 | $this->info('Dumping the autoloaded files and reloading all new files.'); |
||
| 90 | $composer = $this->findComposer(); |
||
| 91 | $process = Process::fromShellCommandline($composer . ' dump-autoload -o'); |
||
| 92 | $process->setTimeout(null); |
||
| 93 | $process->setWorkingDirectory(base_path())->run(); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get the composer command for the environment. |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | private function findComposer() |
||
| 102 | { |
||
| 103 | if (file_exists(getcwd() . '/composer.phar')) { |
||
| 104 | return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar'; |
||
| 105 | } |
||
| 106 | |||
| 107 | return 'composer'; |
||
| 108 | } |
||
| 109 | } |
||
| 110 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.