CliApplication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResolver() 0 4 1
A doException() 0 14 1
1
<?php
2
3
namespace Micro\Cli;
4
5
use Micro\base\Application;
6
use Micro\Base\Exception;
7
use Micro\Cli\Consoles\DefaultConsoleCommand;
8
use Micro\Web\ResponseInjector;
9
use Psr\Http\Message\ResponseInterface;
10
11
12
// всё что нужно для CLI
13
class CliApplication extends Application
14
{
15
    /**
16
     * @return mixed
17
     */
18
    public function getResolver()
19
    {
20
        return new CliResolver;
21
    }
22
23
    /**
24
     * Run application with error
25
     *
26
     * @param \Exception $e
27
     * @return ResponseInterface
28
     * @throws \InvalidArgumentException|\RuntimeException|Exception
29
     */
30
    protected function doException(\Exception $e)
31
    {
32
        $command = new DefaultConsoleCommand();
33
        $command->data = '"Error #' . $e->getCode() . ' - ' . $e->getMessage() . '"';
34
        $command->execute();
35
36
        $response = (new ResponseInjector)->build();
37
        $response = $response->withHeader('status', (string)(int)$command->result); // TODO: hack for select cli stream
38
39
        $stream = $response->getBody();
40
        $stream->write($command->message);
41
42
        return $response->withBody($stream);
43
    }
44
}