CategoryRequest::authorize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Requests;
4
5
use App\Category;
6
7
class CategoryRequest extends Request
8
{
9
    /**
10
     * Determine if the user is authorized to make this request.
11
     *
12
     * @return bool
13
     */
14 2
    public function authorize()
15
    {
16 2
        return true;
17
    }
18
19
    /**
20
     * Get the validation rules that apply to the request.
21
     *
22
     * @return array
23
     */
24 2
    public function rules()
25
    {
26
        return [
27 2
        ];
28
    }
29
30
    /**
31
     * Build Query with Filters
32
     * @return Category
33
     */
34 2
    public function getCategoryByFilters()
35
    {
36 2
        $category = Category::where('isTeam', '=', $this->isTeam)
37 2
            ->where('gender', '=', $this->gender)
38 2
            ->where('gradeCategory', '=', $this->gradeCategory)
39 2
            ->where('ageCategory', '=', $this->ageCategory);
40
41 2
        $this->has('ageMin') ? $category = $category->where('ageMin', $this->ageMin) : '';
42 2
        $this->has('ageMax') ? $category = $category->where('ageMax', $this->ageMax) : '';
43 2
        $this->has('gradeMin') ? $category = $category->where('gradeMin', $this->gradeMin) : '';
44 2
        $this->has('gradeMax') ? $category = $category->where('gradeMax', $this->gradeMax) : '';
45
46 2
        return $category->select('name')->first() ?? new Category();
47
    }
48
49
}
50