CommandBuilder::build()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 1
crap 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