Passed
Push — master ( aa1e46...8f73fe )
by n
01:50
created

CommandFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 3
1
<?php
2
3
namespace N1215\CakeCandle\Console;
4
5
use Cake\Console\Command;
6
use Cake\Console\CommandFactoryInterface;
7
use Cake\Console\Shell;
8
use InvalidArgumentException;
9
use N1215\CakeCandle\ContainerBagLocator;
10
11
/**
12
 * This is a factory for creating Command and Shell instances.
13
 *
14
 * This factory can be replaced or extended if you need to customize building
15
 * your command and shell objects.
16
 */
17
final class CommandFactory implements CommandFactoryInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22 4
    public function create($className)
23
    {
24 4
        $command = ContainerBagLocator::get()->get($className);
25 4
        if (!($command instanceof Command) && !($command instanceof Shell)) {
26 2
            $valid = implode('` or `', [Shell::class, Command::class]);
27 2
            $message = sprintf('Class `%s` must be an instance of `%s`.', $className, $valid);
28 2
            throw new InvalidArgumentException($message);
29
        }
30
31 2
        return $command;
32
    }
33
}
34