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

ValidationError::getCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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