1 | <?php declare(strict_types=1); |
||
25 | class Application |
||
26 | { |
||
27 | private const MIN_PADDING_SIZE = 30; |
||
28 | |||
29 | /** |
||
30 | * @var CLImate |
||
31 | */ |
||
32 | public $cliMate; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $rootDirectory; |
||
38 | |||
39 | /** |
||
40 | * @var ApplicationFactory |
||
41 | */ |
||
42 | private $applicationFactory; |
||
43 | |||
44 | /** |
||
45 | * @var Duration |
||
46 | */ |
||
47 | private $duration; |
||
48 | |||
49 | public function __construct(string $rootDirectory) |
||
56 | |||
57 | /** |
||
58 | * Main entry point to execute the application. |
||
59 | * |
||
60 | * @return int exit code |
||
61 | */ |
||
62 | public function run(array $inputArgs): int |
||
63 | { |
||
64 | try { |
||
65 | $config = $this->prepare($inputArgs); |
||
66 | |||
67 | $scriptFinder = $this->applicationFactory->createScriptFinder($config); |
||
68 | |||
69 | $this->executeScript($scriptFinder, $config); |
||
70 | |||
71 | $this->showListing($scriptFinder->getAllVisibleScripts()); |
||
72 | |||
73 | throw ExitSignal::success(); |
||
74 | } catch (PshErrorMessage $error) { |
||
75 | $this->notifyError("\n" . $error->getMessage() . "\n"); |
||
76 | |||
77 | return ExitSignal::error()->signal(); |
||
78 | } catch (ExitSignal $signal) { |
||
79 | return $signal->signal(); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @param Script[] $scripts |
||
85 | */ |
||
86 | private function showListing(array $scripts): void |
||
87 | { |
||
88 | $this->cliMate->green()->bold('Available commands:')->br(); |
||
89 | |||
90 | if (!count($scripts)) { |
||
91 | $this->cliMate->yellow()->bold("-> Currently no scripts available\n"); |
||
92 | |||
93 | return; |
||
94 | } |
||
95 | |||
96 | $paddingSize = $this->getPaddingSize($scripts); |
||
97 | $padding = $this->cliMate->padding($paddingSize)->char(' '); |
||
98 | |||
99 | $scriptEnvironment = 'default'; |
||
100 | foreach ($scripts as $script) { |
||
101 | if ($script->getEnvironment() !== $scriptEnvironment) { |
||
102 | $scriptEnvironment = $script->getEnvironment(); |
||
103 | $this->cliMate->green()->br()->bold(($scriptEnvironment ?? 'default') . ':'); |
||
104 | } |
||
105 | |||
106 | $padding |
||
107 | ->label(sprintf('<bold> - %s</bold>', $script->getName())) |
||
108 | ->result(sprintf('<dim>%s</dim>', $script->getDescription())); |
||
109 | } |
||
110 | |||
111 | $this->cliMate->green()->bold(sprintf("\n %s script(s) available\n", count($scripts))); |
||
112 | } |
||
113 | |||
114 | private function execute(Script $script, Config $config, ScriptFinder $scriptFinder): void |
||
133 | |||
134 | /** |
||
135 | * @param $string |
||
136 | */ |
||
137 | private function notifySuccess(string $string): void |
||
141 | |||
142 | /** |
||
143 | * @param $string |
||
144 | */ |
||
145 | private function notifyError(string $string): void |
||
149 | |||
150 | private function getPaddingSize(array $scripts): int |
||
156 | |||
157 | private function showAutocompleteListing(Config $config): void |
||
170 | |||
171 | private function showScriptNotFoundListing(string $scriptName, ScriptFinder $scriptFinder): void |
||
183 | |||
184 | private function printHead(Config $config, ApplicationConfigLogger $logger): void |
||
198 | |||
199 | private function validateConfig(Config $config, ?string $environment = null): void |
||
216 | |||
217 | private function printMissingRequiredVariable(RequiredValue $requiredVariable): void |
||
232 | |||
233 | private function prepare(array $inputArgs): Config |
||
251 | |||
252 | private function executeScript(ScriptFinder $scriptFinder, Config $config): void |
||
273 | } |
||
274 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.