Passed
Pull Request — master (#46)
by
unknown
04:36
created

CategoryController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Category;
6
use App\Http\Requests\CategoryRequest;
7
use Illuminate\Http\Request;
8
9
10
class CategoryController extends Controller
11
{
12
13
    /**
14
     * Show the form for creating a new resource.
15
     *
16
     * @return \Illuminate\Http\Response
17
     */
18
    public function create()
19
    {
20
        return view('categories.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('categories.create') returns the type Illuminate\Contracts\Vie...ry|Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
21
    }
22
23
    /**
24
     * Show the form for creating a new resource.
25
     *
26
     * @param Request|CategoryRequest $request
27
     * @return \Illuminate\Database\Eloquent\Model
28
     */
29
30 2
    public function store(CategoryRequest $request)
31
    {
32 2
        $category = $request->getCategoryByFilters();
33
34 2
        $category->isTeam = $request->isTeam;
35 2
        $category->gender = $request->gender;
36 2
        $category->ageCategory = $request->ageCategory;
37 2
        $category->ageMin = $request->ageMin;
38 2
        $category->ageMax = $request->ageMax;
39 2
        $category->gradeCategory = $request->gradeCategory;
0 ignored issues
show
Bug Best Practice introduced by
The property gradeCategory does not exist on App\Category. Since you implemented __set, consider adding a @property annotation.
Loading history...
40 2
        $category->gradeMin = $request->gradeMin;
41 2
        $category->gradeMax = $request->gradeMax;
42 2
        $category->name = $category->buildName();
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\Category. Since you implemented __set, consider adding a @property annotation.
Loading history...
43
44 2
        $newCategoryName = Category::firstOrCreate($category->toArray());
45
46 2
        return $newCategoryName;
47
    }
48
}
49