Command   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A launch() 0 8 1
A interpretOutput() 0 4 1
A execute() 0 8 2
A unauthorize() 0 6 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