CommandBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 28
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 21 4
1
<?php
2
/**
3
 * This file is part of the Symfony Console DI package.
4
 *
5
 * (c) Stéphane Demonchaux <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SymfonyDiConsole;
11
12
class CommandBuilder
13
{
14
    /**
15
     * @param string $diConsoleCommand
16
     * @return BaseCommand
17
     */
18 7
    public static function build($diConsoleCommandClass)
19
    {
20 7
        if (is_string($diConsoleCommandClass) === false) {
21 2
            throw new InvalidCommandException(
22 2
                sprintf('Arg must be a string "%s" given', gettype($diConsoleCommandClass))
23 2
            );
24 5
        } elseif (class_exists($diConsoleCommandClass) === false) {
25 1
            throw new InvalidCommandException(
26 1
                sprintf('Class "%s" does not exist', $diConsoleCommandClass)
27 1
            );
28 4
        } elseif (is_subclass_of($diConsoleCommandClass, '\SymfonyDiConsole\SymfonyDiConsoleInterface') === false) {
29 1
            throw new InvalidCommandException(
30 1
                sprintf(
31 1
                    'Class "%s" must be instance of \SymfonyDiConsole\SymfonyDiConsoleInterface',
32
                    $diConsoleCommandClass
33 1
                )
34 1
            );
35
        }
36
37 3
        return new BaseCommand($diConsoleCommandClass);
38
    }
39
}
40