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

ValidationError   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getViolationsArray() 0 9 2
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