DocumentRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 57
loc 57
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 5 5 1
A rules() 12 12 1
A attributes() 8 8 1
A messages() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Webfactor\Laravel\Backpack\Documents\Requests;
4
5
use App\Http\Requests\Request;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Illuminate\Validation\Rule;
8
9 View Code Duplication
class DocumentRequest extends FormRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        // only allow updates if the user is logged in
19
        return backpack_auth()->check();
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<strin...n\Rules\Unique>|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
26
     */
27
    public function rules()
28
    {
29
        return [
30
            'type'  => [
31
                'required',
32
                Rule::in(config('webfactor.documents.types')),
33
                Rule::unique('documents')
34
            ],
35
            'title' => 'required|min:5|max:255',
36
            'body'  => 'required|string'
37
        ];
38
    }
39
40
    /**
41
     * Get the validation attributes that apply to the request.
42
     *
43
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,\Illuminate...ator|string|array|null>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
44
     */
45
    public function attributes()
46
    {
47
        return [
48
            'type' => trans('webfactor::documents.type'),
49
            'title' => trans('webfactor::documents.title'),
50
            'body' => trans('webfactor::documents.body')
51
        ];
52
    }
53
54
    /**
55
     * Get the validation messages that apply to the request.
56
     *
57
     * @return array
58
     */
59
    public function messages()
60
    {
61
        return [
62
            //
63
        ];
64
    }
65
}
66