Passed
Pull Request — development (#682)
by Nick
07:09
created

ValidationException::getViolations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
/**
10
 * Class ValidationException
11
 *
12
 * @package Oc\Validator\Exception
0 ignored issues
show
introduced by
Unexpected tag type @package in doc block
Loading history...
13
 */
14
class ValidationException extends Exception
15
{
16
    /**
17
     * @var ConstraintViolationListInterface
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
18
     */
19
    protected $violations;
20
21
    /**
22
     * @param ConstraintViolationListInterface $violations
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
23
     */
24
    public function __construct(ConstraintViolationListInterface $violations)
25
    {
26
        $this->setViolations($violations);
27
28
        parent::__construct((string) $this);
0 ignored issues
show
introduced by
No whitespace should be between cast and variable.
Loading history...
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function __toString()
35
    {
36
        $output = '';
37
38
        /**
39
         * @var ConstraintViolationInterface $violation
0 ignored issues
show
introduced by
ConstraintViolationInterface => \Symfony\Component\Validator\ConstraintViolationInterface
Loading history...
40
         */
41
        foreach ($this->violations as $violation) {
42
            $output .= $violation->getPropertyPath() . ': ' . $violation->getMessage() . PHP_EOL;
43
        }
44
45
        return $output;
46
    }
47
48
    /**
49
     * @param ConstraintViolationListInterface $violations
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
50
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
51
    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...
52
    {
53
        $this->violations = $violations;
54
    }
55
56
    /**
57
     * Returns all violations.
58
     *
59
     * @return ConstraintViolationListInterface
0 ignored issues
show
introduced by
ConstraintViolationListInterface => \Symfony\Component\Validator\ConstraintViolationListInterface
Loading history...
60
     */
61
    public function getViolations()
62
    {
63
        return $this->violations;
64
    }
65
}
66