1 | <?php declare(strict_types = 1); |
||
2 | |||
3 | namespace Suilven\PHPTravisEnhancer\Runner; |
||
4 | |||
5 | use League\CLImate\CLImate; |
||
6 | use splitbrain\phpcli\Options; |
||
7 | use Suilven\PHPTravisEnhancer\Task\AddDuplicationCheckTask; |
||
8 | use Suilven\PHPTravisEnhancer\Task\AddPHPLintTask; |
||
9 | use Suilven\PHPTravisEnhancer\Terminal\TerminalHelper; |
||
10 | |||
11 | class Runner |
||
12 | { |
||
13 | |||
14 | use TerminalHelper; |
||
15 | |||
16 | /** @var \League\CLImate\CLImate */ |
||
17 | private $climate; |
||
18 | |||
19 | public function __construct() |
||
20 | { |
||
21 | $this->climate = new CLImate(); |
||
22 | $this->climate->clear(); |
||
23 | } |
||
24 | |||
25 | |||
26 | public function run(Options $options): void |
||
27 | { |
||
28 | $this->climate->bold('PHP Travis Enhancer - Audit Your Code To The Max'); |
||
29 | |||
30 | $this->climate->black()->bold('COMMANDS:'); |
||
31 | $this->climate->green($options->getCmd()); |
||
32 | |||
33 | |||
34 | switch ($options->getCmd()) { |
||
35 | case 'phpstan': |
||
36 | $this->addPhpStan(); |
||
37 | |||
38 | break; |
||
39 | case 'lint': |
||
40 | $this->addPhpLint(); |
||
41 | |||
42 | break; |
||
43 | case 'phpcs': |
||
44 | $this->addCodingStandardsCheck(); |
||
45 | |||
46 | break; |
||
47 | case 'psalm': |
||
48 | $this->addPsalm(); |
||
49 | |||
50 | break; |
||
51 | case 'duplication': |
||
52 | $this->addDuplicationCheck(); |
||
53 | |||
54 | break; |
||
55 | case 'all': |
||
56 | $this->addCodingStandardsCheck(); |
||
57 | $this->addDuplicationCheck(); |
||
58 | $this->addPhpLint(); |
||
59 | $this->addPhpStan(); |
||
60 | $this->addPsalm(); |
||
61 | |||
62 | break; |
||
63 | default: |
||
64 | $this->climate->red('No known command was called, we show the default help instead:'); |
||
65 | echo $options->help(); |
||
66 | exit; |
||
0 ignored issues
–
show
|
|||
67 | } |
||
68 | } |
||
69 | |||
70 | |||
71 | private function addCodingStandardsCheck(): void |
||
72 | { |
||
73 | $this->climate->black('Trying to add coding standards check '); |
||
74 | $task = new \Suilven\PHPTravisEnhancer\Task\AddPHPCSTask(); |
||
75 | $task->run(); |
||
76 | } |
||
77 | |||
78 | |||
79 | private function addDuplicationCheck(): void |
||
80 | { |
||
81 | $this->climate->black('Trying to add duplication checker '); |
||
82 | $task = new AddDuplicationCheckTask(); |
||
83 | $task->run(); |
||
84 | } |
||
85 | |||
86 | |||
87 | private function addPhpLint(): void |
||
88 | { |
||
89 | $this->climate->black('Trying to add linting '); |
||
90 | $task = new AddPHPLintTask(); |
||
91 | $task->run(); |
||
92 | } |
||
93 | |||
94 | |||
95 | private function addPhpStan(): void |
||
96 | { |
||
97 | $this->climate->black('Trying to add PHPStan '); |
||
98 | $task = new \Suilven\PHPTravisEnhancer\Task\AddPHPStanTask(); |
||
99 | $task->run(); |
||
100 | } |
||
101 | |||
102 | |||
103 | private function addPsalm(): void |
||
104 | { |
||
105 | $this->climate->black('Trying to add Psalm '); |
||
106 | $task = new \Suilven\PHPTravisEnhancer\Task\AddPsalmTask(); |
||
107 | $task->run(); |
||
108 | } |
||
109 | } |
||
110 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.