Completed
Pull Request — master (#37)
by Peter
23:57
created

ValidationException::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.037
1
<?php
2
3
namespace TreeHouse\IoBundle\Exception;
4
5
use Symfony\Component\Validator\ConstraintViolationListInterface;
6
7
class ValidationException extends \Exception
8
{
9
    /**
10
     * @var ConstraintViolationListInterface
11
     */
12
    protected $violations;
13
14
    /**
15
     * @param ConstraintViolationListInterface $violations
16
     */
17 2
    public function setViolations(ConstraintViolationListInterface $violations)
18
    {
19 2
        $this->violations = $violations;
20 2
    }
21
22
    /**
23
     * @return ConstraintViolationListInterface
24
     */
25
    public function getViolations()
26
    {
27
        return $this->violations;
28
    }
29
30
    /**
31
     * @param ConstraintViolationListInterface $violations
32
     *
33
     * @return ValidationException
34
     */
35 2
    public static function create(ConstraintViolationListInterface $violations)
36
    {
37 2
        $exception = new static((string) $violations);
38 2
        $exception->setViolations($violations);
39
40 2
        return $exception;
41
    }
42
}
43