InvalidCommandException::getViolations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
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\Bundle\Middleware;
4
5
use League\Tactician\Exception\Exception;
6
use Symfony\Component\Validator\ConstraintViolationListInterface;
7
8
class InvalidCommandException extends \Exception implements Exception
9
{
10
    /**
11
     * @var object
12
     */
13
    protected $command;
14
15
    /**
16
     * @var ConstraintViolationListInterface
17
     */
18
    protected $violations;
19
20
    /**
21
     * @param object $command
22
     * @param ConstraintViolationListInterface $violations
23
     *
24
     * @return static
25
     */
26 3
    public static function onCommand($command, ConstraintViolationListInterface $violations)
27
    {
28 3
        $exception = new static(
29 3
            'Validation failed for ' . get_class($command) .
30 3
            ' with ' . $violations->count() . ' violation(s).'
31
        );
32
33 3
        $exception->command    = $command;
34 3
        $exception->violations = $violations;
35
36 3
        return $exception;
37
    }
38
39
    /**
40
     * @return object
41
     */
42 3
    public function getCommand()
43
    {
44 3
        return $this->command;
45
    }
46
47
    /**
48
     * @return ConstraintViolationListInterface
49
     */
50 3
    public function getViolations()
51
    {
52 3
        return $this->violations;
53
    }
54
}
55