Completed
Push — master ( e3e09e...fb3f67 )
by Dmitrij
03:22
created

GetCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
A __construct() 0 4 1
A constructOptions() 0 12 2
A constructArguments() 0 12 2
1
<?php
2
3
namespace HotRodCli\Api;
4
5
use HotRodCli\AppContainer;
6
use HotRodCli\Commands\BaseCommand;
7
8
class GetCommand
9
{
10
    protected $container;
11
12
    protected $commands;
13
14
    public function __construct(AppContainer $appContainer)
15
    {
16
        $this->container = $appContainer;
17
        $this->commands = $this->container->resolve('commands');
18
    }
19
20
    public function __invoke($args)
21
    {
22
        /** @var BaseCommand $command */
23
        $command = $this->container->resolve($this->commands[$args['command']]);
24
25
        return json_encode([
26
            'arguments' => $this->constructArguments($command),
27
            'options' => $this->constructOptions($command)
28
        ]);
29
    }
30
31
    public function constructArguments(BaseCommand $command)
32
    {
33
        $result = [];
34
35
        foreach ($command->getDefinition()->getArguments() as $argument) {
36
            $result[] = [
37
                'name' => $argument->getName(),
38
                'description' => $argument->getDescription()
39
            ];
40
        }
41
42
        return $result;
43
    }
44
45
    public function constructOptions(BaseCommand $command)
46
    {
47
        $result = [];
48
49
        foreach ($command->getDefinition()->getOptions() as $option) {
50
            $result[] = [
51
                'name' => $option->getName(),
52
                'description' => $option->getDescription()
53
            ];
54
        }
55
56
        return $result;
57
    }
58
}
59