InvalidCommandException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
/**
3
 * This file is part of the phpspec-console package.
4
 * (c) 2017 Timo Michna <timomichna/yahoo.de>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Tidal\PhpSpec\ConsoleExtension\Exception;
11
12
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\CommandInterface;
13
use InvalidArgumentException;
14
use Throwable;
15
16
class InvalidCommandException extends InvalidArgumentException
17
{
18
    private const MESSAGE_PATTERN = "Command '%s' is not accepted by Configurator";
19
20
    /**
21
     * InvalidCommandException constructor.
22
     * @param CommandInterface $command
23
     * @param int $code
24
     * @param Throwable|null $previous
25
     */
26
    public function __construct(CommandInterface $command, int $code = 0, Throwable $previous = null)
27
    {
28
        parent::__construct(
29
            self::generateMessage(
30
                get_class($command)
31
            ),
32
            $code,
33
            $previous
34
        );
35
    }
36
37
    /**
38
     * @param string $commandClass
39
     * @return string
40
     */
41
    private static function generateMessage(string $commandClass)
42
    {
43
        return(sprintf(
44
            self::MESSAGE_PATTERN,
45
            $commandClass
46
        ));
47
    }
48
}
49