Completed
Push — master ( 4bd9c5...bfabef )
by ARCANEDEV
02:55
created

FormRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 57
ccs 0
cts 16
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
rules() 0 1 ?
A formatErrors() 0 15 3
1
<?php namespace Arcanedev\Support\Bases;
2
3
use Illuminate\Contracts\Validation\Validator;
4
use Illuminate\Foundation\Http\FormRequest as BaseFormRequest;
5
6
/**
7
 * Class     FormRequest
8
 *
9
 * @package  Arcanedev\Support\Laravel
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
abstract class FormRequest extends BaseFormRequest
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * The errors format.
20
     *
21
     * @var string|null
22
     */
23
    protected $errorsFormat = null;
24
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Main Functions
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    /**
30
     * Determine if the user is authorized to make this request.
31
     *
32
     * @return bool
33
     */
34
    public function authorize()
35
    {
36
        return false;
37
    }
38
39
    /**
40
     * Get the validation rules that apply to the request.
41
     *
42
     * @return array
43
     */
44
    abstract public function rules();
45
46
    /* ------------------------------------------------------------------------------------------------
47
     |  Other Functions
48
     | ------------------------------------------------------------------------------------------------
49
     */
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function formatErrors(Validator $validator)
54
    {
55
        if (is_null($this->errorsFormat)) {
56
            return parent::formatErrors($validator);
57
        }
58
59
        $errors   = [];
60
        $messages = $validator->getMessageBag();
61
62
        foreach ($messages->keys() as $key) {
63
            $errors[$key] = $messages->get($key, $this->errorsFormat);
64
        }
65
66
        return $errors;
67
    }
68
}
69