Passed
Push — master ( 0d595f...2b1d04 )
by Oliver
02:10
created

DocumentUpdateRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 57
loc 57
ccs 0
cts 14
cp 0
rs 10
c 1
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\Validation\Rule;
7
8 View Code Duplication
class DocumentUpdateRequest extends \Backpack\CRUD\app\Http\Requests\CrudRequest
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...
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        // only allow updates if the user is logged in
18
        return \Auth::check();
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array|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...
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'type'  => [
30
                'required',
31
                Rule::in(config('webfactor.documents.types')),
32
                Rule::unique('documents')->ignore($this->id)
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Webfactor\Laravel...\DocumentUpdateRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
33
            ],
34
            'title' => 'required|min:5|max:255',
35
            'body'  => 'required|string'
36
        ];
37
    }
38
39
    /**
40
     * Get the validation attributes that apply to the request.
41
     *
42
     * @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...
43
     */
44
    public function attributes()
45
    {
46
        return [
47
            'type' => trans('webfactor::documents.type'),
48
            'title' => trans('webfactor::documents.title'),
49
            'body' => trans('webfactor::documents.body')
50
        ];
51
    }
52
53
    /**
54
     * Get the validation messages that apply to the request.
55
     *
56
     * @return array
57
     */
58
    public function messages()
59
    {
60
        return [
61
            //
62
        ];
63
    }
64
}
65