Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
CliApp
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 init
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 process
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 handleException
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Dynart\Micro;
4
5/**
6 * Handles CLI commands
7 * @package Dynart\Micro
8 */
9class CliApp extends App {
10
11    protected CliCommands $commands;
12
13    protected CliOutput $output;
14
15    public function __construct(array $configPaths) {
16        parent::__construct($configPaths);
17        Micro::add(CliCommands::class);
18        Micro::add(CliOutput::class);
19    }
20
21    public function init(): void {
22        $this->commands = Micro::get(CliCommands::class);
23    }
24
25    public function process(): void {
26        list($callable, $params) = $this->commands->matchCurrent();
27        if ($callable) {
28            $callable = Micro::getCallable($callable);
29            if (empty($params)) {
30                $content = call_user_func($callable);
31            } else {
32                $content = call_user_func_array($callable, [$params]);
33            }
34            $this->finish($content);
35        } else {
36            error_log("Unknown command: ".$this->commands->current());
37            $this->finish(1);
38        }
39    }
40
41    protected function handleException(\Exception $e): void {
42        parent::handleException($e);
43        $this->finish(1);
44    }
45}