ValidationFailedException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 4
cts 6
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A data() 0 4 1
1
<?php
2
3
namespace Flugg\Responder\Exceptions\Http;
4
5
use Illuminate\Contracts\Validation\Validator;
6
7
/**
8
 * An exception thrown whan validation fails. This exception replaces Laravel's
9
 * [\Illuminate\Validation\ValidationException].
10
 *
11
 * @package flugger/laravel-responder
12
 * @author  Alexander Tømmerås <[email protected]>
13
 * @license The MIT License
14
 */
15
class ValidationFailedException extends HttpException
16
{
17
    /**
18
     * An HTTP status code.
19
     *
20
     * @var int
21
     */
22
    protected $status = 422;
23
24
    /**
25
     * An error code.
26
     *
27
     * @var string|null
28
     */
29
    protected $errorCode = 'validation_failed';
30
31
    /**
32
     * A validator for fetching validation messages.
33
     *
34
     * @var \Illuminate\Contracts\Validation\Validator
35
     */
36
    protected $validator;
37
38
    /**
39
     * Construct the exception class.
40
     *
41
     * @param \Illuminate\Contracts\Validation\Validator $validator
42
     */
43 1
    public function __construct(Validator $validator)
44
    {
45 1
        $this->validator = $validator;
46
47 1
        parent::__construct();
48 1
    }
49
50
    /**
51
     * Retrieve the error data.
52
     *
53
     * @return array|null
54
     */
55
    public function data()
56
    {
57
        return ['fields' => $this->validator->getMessageBag()->toArray()];
58
    }
59
}