CategoryController::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Retosteffen\LaravelBlog\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Retosteffen\LaravelBlog\Models\Category;
7
use Retosteffen\LaravelBlog\Models\LaravelBlog;
8
9
class CategoryController
10
{
11
    public function index(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
    {
13
        $categories = Category::all()->sortBy('name', SORT_NATURAL | SORT_FLAG_CASE);
14
15
        return view('laravel-blog::category.index', compact('categories'));
16
    }
17
18
    public function create(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20
        return view('laravel-blog::category.create');
21
    }
22
23
    public function store(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $attributes = request()->validate([
26
            'name'=>['required'],
27
        ]);
28
29
        $category = Category::create($attributes);
0 ignored issues
show
Unused Code introduced by
$category is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
31
        return redirect()->route('categories');
32
    }
33
34 View Code Duplication
    public function show(Category $category)
0 ignored issues
show
Duplication introduced by
This method 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...
35
    {
36
        $item = $category;
37
        $posts = LaravelBlog::where('published', '=', true)->where('category_id', '=', $item->id)->orderBy('published_at', 'desc')->get();
38
39
        return view('laravel-blog::archive', compact('item', 'posts'));
40
    }
41
42
    public function edit(Category $category)
43
    {
44
        return view('laravel-blog::category.edit', compact('category'));
45
    }
46
47 View Code Duplication
    public function update(Request $request, Category $category)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method 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...
48
    {
49
        $attributes = request()->validate([
50
            'name'=>['required'],
51
        ]);
52
53
        $category->update($attributes);
54
55
        return redirect()->route('categories');
56
    }
57
58
    public function destroy(Category $category)
59
    {
60
        $category->delete();
61
62
        return redirect()->route('categories');
63
    }
64
}
65