CommandFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

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