InvalidCommandException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A generateMessage() 0 7 1
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