CanNotInvokeHandlerException::getCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace League\Tactician\Exception;
4
5
use BadMethodCallException;
6
7
/**
8
 * Thrown when a specific handler object can not be used on a command object.
9
 *
10
 * The most common reason is the receiving method is missing or incorrectly
11
 * named.
12
 */
13 View Code Duplication
class CanNotInvokeHandlerException extends BadMethodCallException implements Exception
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @var mixed
17
     */
18
    private $command;
19
20
    /**
21
     * @param mixed $command
22
     * @param string $reason
23
     *
24
     * @return static
25
     */
26 12
    public static function forCommand($command, $reason)
27
    {
28 12
        $type =  is_object($command) ? get_class($command) : gettype($command);
29
30 12
        $exception = new static(
31 12
            'Could not invoke handler for command ' . $type .
32 12
            ' for reason: ' . $reason
33
        );
34 12
        $exception->command = $command;
35
36 12
        return $exception;
37
    }
38
39
    /**
40
     * Returns the command that could not be invoked
41
     *
42
     * @return mixed
43
     */
44 11
    public function getCommand()
45
    {
46 11
        return $this->command;
47
    }
48
}
49