Completed
Push — master ( d44ef5...c7e879 )
by Fèvre
12s
created

CategoryController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 19.51 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 8
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 8 8 1
A show() 0 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Xetaravel\Http\Controllers\Discuss;
3
4
use Illuminate\View\View;
5
use Xetaravel\Models\DiscussCategory;
6
use Xetaravel\Models\DiscussConversation;
7
8
class CategoryController extends Controller
9
{
10
    /**
11
     * View all categories.
12
     *
13
     * @return \Illuminate\View\View
14
     */
15 View Code Duplication
    public function index(): View
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...
16
    {
17
        $categories = DiscussCategory::orderBy('title', 'asc')->get();
18
19
        $breadcrumbs = $this->breadcrumbs->addCrumb('All Categories', route('discuss.category.index'));
20
21
        return view('Discuss::category.index', compact('categories', 'breadcrumbs'));
22
    }
23
24
    /**
25
     * Display all conversations related to the category.
26
     *
27
     * @return \Illuminate\View\View
28
     */
29
    public function show(string $slug, int $id): View
0 ignored issues
show
Unused Code introduced by
The parameter $slug 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...
30
    {
31
        $category = DiscussCategory::findOrFail($id);
32
33
        $conversations = DiscussConversation::where('category_id', $category->getKey())
34
            ->with('User', 'Category', 'FirstPost', 'LastPost')
35
            ->orderBy('is_pinned', 'desc')
36
            ->orderBy('created_at', 'desc')
37
            ->paginate(config('xetaravel.pagination.discuss.conversation_per_page'));
38
39
        $this->breadcrumbs->addCrumb('Categories', route('discuss.category.index'));
40
41
        $breadcrumbs = $this->breadcrumbs->addCrumb(
42
            e($category->title),
43
            route('discuss.category.show', ['slug' => $category->slug,'id' => $category->getKey()])
44
        );
45
46
        return view('Discuss::category.show', compact('breadcrumbs', 'conversations', 'category'));
47
    }
48
}
49