Completed
Pull Request — master (#9)
by Adam
05:57
created

AurynCommandFactory::make()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Equip\Queue\Command;
4
5
use Auryn\Injector;
6
use Equip\Command\CommandInterface;
7
use Equip\Queue\Exception\CommandException;
8
9
class AurynCommandFactory implements CommandFactoryInterface
10
{
11
    /**
12
     * @var Injector
13
     */
14
    private $injector;
15
16 3
    public function __construct(Injector $injector)
17
    {
18 3
        $this->injector = $injector;
19 3
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24 3
    public function make($command)
25
    {
26 3
        if (!class_exists($command)) {
27 1
            throw CommandException::notFound($command);
28
        }
29
30 2
        $command = $this->injector->make($command);
31
32 2
        if (!($command instanceof CommandInterface)) {
33 1
            throw CommandException::invalidCommand($command);
34
        }
35
36 1
        return $command;
37
    }
38
}
39