Completed
Push — master ( 7b4134...6183d2 )
by David
04:31
created

AdminController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 31.25 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 9
Bugs 2 Features 3
Metric Value
wmc 8
c 9
b 2
f 3
lcom 1
cbo 6
dl 20
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 17 2
A forums() 0 11 2
A categories() 10 10 2
A forumForm() 10 10 2

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 namespace Taskforcedev\LaravelForum\Http\Controllers;
2
3
use \Schema;
4
use Taskforcedev\LaravelForum\Database\Migrator;
5
use Taskforcedev\LaravelForum\Forum;
6
use Taskforcedev\LaravelForum\ForumPost;
7
use Taskforcedev\LaravelForum\ForumReply;
8
use Taskforcedev\LaravelForum\ForumCategory;
9
10
/**
11
 * Class AdminController
12
 * @package Taskforcedev\LaravelForum\Http\Controllers
13
 */
14
class AdminController extends BaseController
15
{
16
    /**
17
     * Admin index.
18
     * @return mixed
19
     */
20
    public function index()
21
    {
22
        if (!$this->canAdministrate()) {
23
            return redirect()->route('laravel-forum.index');
24
        }
25
26
        $data = $this->buildData();
27
28
        $data['counts'] = [
29
            'forum' => (new Forum)->getCount(),
30
            'category' => (new ForumCategory)->getCount(),
31
            'post' => (new ForumPost)->getCount(),
32
            'reply' => (new ForumReply)->getCount(),
33
        ];
34
35
        return view('laravel-forum::admin/index', $data);
36
    }
37
38
    /**
39
     * @return mixed
40
     */
41
    public function forums()
42
    {
43
        if (!$this->canAdministrate()) {
44
            return redirect()->route('laravel-forum.index');
45
        }
46
47
        $data = $this->buildData();
48
        $data['categories'] = ForumCategory::all();
49
        $data['forums'] = Forum::orderBy('category_id')->get();
50
        return view('laravel-forum::admin/forums', $data);
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56 View Code Duplication
    public function categories()
57
    {
58
        if (!$this->canAdministrate()) {
59
            return redirect()->route('laravel-forum.index');
60
        }
61
62
        $data = $this->buildData();
63
        $data['categories'] = ForumCategory::all();
64
        return view('laravel-forum::admin/categories', $data);
65
    }
66
67 View Code Duplication
    public function forumForm()
68
    {
69
        if (!$this->canAdministrate()) {
70
            return redirect()->route('laravel-forum.index');
71
        }
72
73
        $data = $this->buildData();
74
        $data['categories'] = ForumCategory::all();
75
        return view('laravel-forum::admin.forum.create', $data);
76
    }
77
}
78