Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 13 |
| TryCatchCommand | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 13 |
| handle | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| launch | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| launchWithCatch | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 8 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Deduplication\Console\Commands; |
| 4 | |
| 5 | use Illuminate\Console\Command; |
| 6 | use Qmp\Laravel\Deduplication\Exceptions\OutputMessageException; |
| 7 | |
| 8 | abstract class TryCatchCommand extends Command |
| 9 | { |
| 10 | /** |
| 11 | * Execute the console command. |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | public function handle(): void |
| 16 | { |
| 17 | if ($this->option('throw-error')) { |
| 18 | $this->launch(); |
| 19 | } else { |
| 20 | $this->launchWithCatch(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Launch command |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | protected function launch() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Launch command with catch for single command use |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | protected function launchWithCatch() : void |
| 39 | { |
| 40 | try { |
| 41 | $this->launch(); |
| 42 | } catch (OutputMessageException $e) { |
| 43 | $this->{$e->getOutputType()}($e->getMessage()); |
| 44 | } catch (\Exception $e) { |
| 45 | $this->error("Line : " . $e->getLine()); |
| 46 | $this->error("File : " . $e->getFile()); |
| 47 | $this->error("Error : " . $e->getMessage()); |
| 48 | } |
| 49 | } |
| 50 | } |