Passed
Push — master ( 9da6fd...0354d3 )
by Rafael
05:30
created

ValidationError::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Exception\Controlled;
12
13
use Symfony\Component\HttpFoundation\Response;
14
use Ynlo\GraphQLBundle\Exception\ControlledError;
15
use Ynlo\GraphQLBundle\Model\ConstraintViolation;
16
use Ynlo\GraphQLBundle\Validator\ConstraintViolationList;
17
18
class ValidationError extends ControlledError
19
{
20
    protected $code = Response::HTTP_UNPROCESSABLE_ENTITY;
21
22
    protected $message = 'Unprocessable Entity';
23
24
    protected $description = 'Validation Error. These errors contains a key "constraintViolations" with all violations.';
25
26
    /**
27
     * @var ConstraintViolationList
28
     */
29
    protected $violations;
30
31
    /**
32
     * ValidationError constructor.
33
     *
34
     * @param ConstraintViolationList $violations
35
     */
36 1
    public function __construct(ConstraintViolationList $violations)
37
    {
38 1
        $this->violations = $violations;
39
40 1
        parent::__construct();
41 1
    }
42
43
    /**
44
     * @return array
45
     */
46 1
    public function getViolationsArray()
47
    {
48 1
        $violations = [];
49
        /** @var ConstraintViolation $v */
50 1
        foreach ($this->violations->all() as $v) {
51 1
            $violations[] = $v->toArray();
52
        }
53
54 1
        return $violations;
55
    }
56
}
57