ValidationException::getErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * ValidationException class file
4
 */
5
6
namespace Graviton\JsonSchemaBundle\Exception;
7
8
/**
9
 * ValidationException
10
 *
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  https://opensource.org/licenses/MIT MIT License
13
 * @link     http://swisscom.ch
14
 */
15
class ValidationException extends \RuntimeException
16
{
17
    /**
18
     * @var ValidationExceptionError[]
19
     */
20
    protected $errors = array();
21
22
    /**
23
     * @param ValidationExceptionError[] $errors errors
24
     */
25
    public function __construct(array $errors)
26
    {
27
        $message = '';
28
29
        foreach ($errors as $error) {
30
            $message .= sprintf('* %s: %s', $error->getProperty(), $error->getMessage()).PHP_EOL;
31
            $this->addError($error);
32
        }
33
34
        parent::__construct(rtrim($message));
35
    }
36
37
    /**
38
     * Add an error
39
     *
40
     * @param ValidationExceptionError $error error
41
     *
42
     * @return void
43
     */
44
    public function addError(ValidationExceptionError $error)
45
    {
46
        $this->errors[] = $error;
47
    }
48
49
    /**
50
     * Returns all errors
51
     *
52
     * @return ValidationExceptionError[] errors
53
     */
54
    public function getErrors()
55
    {
56
        return $this->errors;
57
    }
58
}
59