IssueRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A rules() 0 6 1
A messages() 0 8 1
A getValidatorInstance() 0 13 3
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Http\Requests;
10
11
use Illuminate\Foundation\Http\FormRequest;
12
use GitScrum\Models\Sprint;
13
14
class IssueRequest extends FormRequest
15
{
16
    /**
17
     * Determine if the user is authorized to make this request.
18
     *
19
     * @return bool
20
     */
21
    public function authorize()
22
    {
23
        return true;
24
    }
25
26
    /**
27
     * Get the validation rules that apply to the request.
28
     *
29
     * @return array
30
     */
31
    public function rules()
32
    {
33
        return [
34
            'title' => 'required|min:2|max:255',
35
        ];
36
    }
37
    /**
38
     * Get the error messages for the defined validation rules.
39
     *
40
     * @return array
41
     */
42
    public function messages()
43
    {
44
        return [
45
            'title.required' => trans('Issue cannot be blank'),
46
            'title.min' => trans('Issue must be at least 2 characters'),
47
            'title.max' => trans('Issue must be between 2 and 255 characters'),
48
        ];
49
    }
50
51
    protected function getValidatorInstance()
52
    {
53
        $data = $this->all();
54
55
        if (isset($data['slug_sprint']) && !empty($data['slug_sprint'])) {
56
            $data['sprint_id'] = Sprint::slug($data['slug_sprint'])->first()->id;
57
            unset($data['slug_sprint']);
58
        }
59
60
        $this->getInputSource()->replace($data);
61
62
        return parent::getValidatorInstance();
63
    }
64
}
65