Completed
Push — dev ( 5d63f9...a106a3 )
by Zach
04:08
created

ProjectRequest::rules()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Larafolio\Http\Requests;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Foundation\Http\FormRequest;
7
8 View Code Duplication
class ProjectRequest 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...
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        return true;
18
    }
19
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules(Request $request)
26
    {
27
        $id = $request->input('id');
28
29
        $nameRule = 'required_with:type,links,lines,blocks|unique:projects,name';
30
31
        if ($id) {
32
            $nameRule .= ','.$id;
33
        }
34
35
        return [
36
            'name'          => $nameRule,
37
            'blocks.*.text' => 'required',
38
        ];
39
    }
40
41
    /**
42
     * Error messages for validation rules.
43
     *
44
     * @return array
45
     */
46
    public function messages()
47
    {
48
        return [
49
            'name.required_with'     => 'Project name is required.',
50
            'name.unique'            => 'Project name is already taken.',
51
            'blocks.*.text.required' => 'All blocks must have text.'
52
        ];
53
    }
54
}
55