Command::interpretOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace DeGraciaMathieu\Clike;
4
5
class Command {
6
7
    /**
8
     * Execute a command
9
     * @param  \DeGraciaMathieu\Clike\Contracts\Command $command
10
     * @return array
11
     */
12 3
    public function execute(Contracts\Command $command) :array
13
    {
14 3
        if ($command->authorized()) {
15 2
            return $this->launch($command);
16
        }
17
18 1
        return $this->unauthorize($command);
19
    }
20
21
    /**
22
     * Launch an authorized command
23
     * @param  \DeGraciaMathieu\Clike\Contracts\Command $command
24
     * @return array
25
     */
26 2
    protected function launch(Contracts\Command $command) :array
27
    {
28 2
        $command->process();
29
30 2
        $output = new Outputs\Command($command);
31
32 2
        return $this->interpretOutput($output);
33
    }
34
35
    /**
36
     * Response for a unauthorized command
37
     * @param  \DeGraciaMathieu\Clike\Contracts\Command $command
38
     * @return array
39
     */
40 1
    protected function unauthorize(Contracts\Command $command) :array
41
    {
42 1
        $output = new Outputs\Unauthorize($command);
43
44 1
        return $this->interpretOutput($output);
45
    }
46
47
    /**
48
     * return command response
49
     * @param  \DeGraciaMathieu\Clike\Contracts\Output $output
50
     * @return array
51
     */
52 3
    protected function interpretOutput(Contracts\Output $output) :array
53
    {
54 3
        return Interpreter::read($output);
55
    }
56
}
57