Completed
Push — development ( daed94...13a157 )
by Thomas
18s
created

ValidationException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 13 2
A setViolations() 0 4 1
A getViolations() 0 4 1
1
<?php
2
3
namespace Oc\Validator\Exception;
4
5
use Exception;
6
use Symfony\Component\Validator\ConstraintViolationInterface;
7
use Symfony\Component\Validator\ConstraintViolationListInterface;
8
9
class ValidationException extends Exception
10
{
11
    /**
12
     * @var ConstraintViolationListInterface
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
13
     */
14
    protected $violations;
15
16
    /**
17
     * @param ConstraintViolationListInterface $violations
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
18
     */
19
    public function __construct(ConstraintViolationListInterface $violations)
20
    {
21
        $this->setViolations($violations);
22
23
        parent::__construct((string) $this);
0 ignored issues
show
introduced by
No whitespace should be between cast and variable.
Loading history...
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function __toString()
30
    {
31
        $output = '';
32
33
        /**
34
         * @var ConstraintViolationInterface $violation
0 ignored issues
show
introduced by
ConstraintViolationInterface => \Symfony\Component\Validator\ConstraintViolationInterface
Loading history...
35
         */
36
        foreach ($this->violations as $violation) {
37
            $output .= $violation->getPropertyPath() . ': ' . $violation->getMessage() . PHP_EOL;
38
        }
39
40
        return $output;
41
    }
42
43
    /**
44
     * @param ConstraintViolationListInterface $violations
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
45
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
46
    public function setViolations(ConstraintViolationListInterface $violations)
0 ignored issues
show
introduced by
Method does not have a return void statement in doc block: setViolations
Loading history...
47
    {
48
        $this->violations = $violations;
49
    }
50
51
    /**
52
     * Returns all violations.
53
     *
54
     * @return ConstraintViolationListInterface
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
55
     */
56
    public function getViolations()
57
    {
58
        return $this->violations;
59
    }
60
}
61