Completed
Push — master ( 42a15b...d491ac )
by Paweł
02:03
created

CommandCollector::processCommandServices()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Clearcode\CommandBusConsole;
4
5
class CommandCollector
6
{
7
    /**
8
     * @var CommandReflection[]
9
     */
10
    public $commands = [];
11
12
    /**
13
     * @param array $services
14
     */
15
    public function processCommandServices(array $services)
16
    {
17
        foreach ($services as $service) {
18
            $this->commands[] = CommandReflection::fromClass($service);
19
        }
20
    }
21
22
    public function getCommandByName($commandName)
23
    {
24
        foreach ($this->commands as $command) {
25
            if ($command->commandName == $commandName) {
26
                return $command;
27
            }
28
        }
29
30
        throw new CommandDoesNotExist(sprintf("Command '%s' does not exists", $commandName));
31
    }
32
}
33