Passed
Pull Request — master (#125)
by Erik
05:34
created

ValidationError   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCategory() 0 3 1
A isClientSafe() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
namespace Bakery\Errors;
4
5
use GraphQL\Error\Error;
6
use GraphQL\Error\ClientAware;
7
8
class ValidationError extends Error implements ClientAware
9
{
10
    /**
11
     * The validator instance.
12
     *
13
     * @var \Illuminate\Contracts\Validation\Validator
14
     */
15
    public $validator;
16
17
    /**
18
     * Create a new exception instance.
19
     *
20
     * @param  \Illuminate\Contracts\Validation\Validator  $validator
21
     * @return void
22
     */
23
    public function __construct($validator)
24
    {
25
        parent::__construct($validator->errors()->first());
26
27
        $this->validator = $validator;
28
        $this->extensions['validation'] = $validator->errors();
29
    }
30
31
    /**
32
     * Returns true when exception message is safe to be displayed to a client.
33
     *
34
     * @return bool
35
     * @api
36
     */
37
    public function isClientSafe()
38
    {
39
        return true;
40
    }
41
42
    /**
43
     * Returns string describing a category of the error.
44
     *
45
     * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
46
     *
47
     * @return string
48
     * @api
49
     */
50
    public function getCategory()
51
    {
52
        return 'user';
53
    }
54
}
55