Completed
Push — master ( 1092e2...11ab51 )
by Alexander
06:55
created

ValidationFailedException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Flugg\Responder\Exceptions\Http;
4
5
use Illuminate\Contracts\Validation\Validator;
6
7
/**
8
 * An exception replacing Laravel's \Illuminate\Validation\ValidationException.
9
 *
10
 * @package flugger/laravel-responder
11
 * @author  Alexander Tømmerås <[email protected]>
12
 * @license The MIT License
13
 */
14
class ValidationFailedException extends ApiException
15
{
16
    /**
17
     * The HTTP status code.
18
     *
19
     * @var int
20
     */
21
    protected $statusCode = 422;
22
23
    /**
24
     * The error code used for API responses.
25
     *
26
     * @var string
27
     */
28
    protected $errorCode = 'validation_failed';
29
30
    /**
31
     * The validator instance.
32
     *
33
     * @var Validator
34
     */
35
    protected $validator;
36
37
    /**
38
     * Create a new exception instance.
39
     *
40
     * @param Validator $validator
41
     */
42
    public function __construct(Validator $validator)
43
    {
44
        $this->validator = $validator;
45
46
        parent::__construct();
47
    }
48
49
    /**
50
     * Get the error data.
51
     *
52
     * @return array|null
53
     */
54
    public function getData()
55
    {
56
        return ['fields' => $this->validator->getMessageBag()->toArray()];
57
    }
58
}