TagController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 0
dl 24
loc 93
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 6 1
A create() 0 4 1
A store() 8 8 1
A edit() 0 4 1
A update() 8 8 1
A destroy() 8 8 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 namespace Modules\Blog\Http\Controllers\Admin;
2
3
use Illuminate\Http\Request;
4
use Laracasts\Flash\Flash;
5
use Modules\Blog\Entities\Tag;
6
use Modules\Blog\Repositories\TagRepository;
7
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
8
9
class TagController extends AdminBaseController
10
{
11
    /**
12
     * @var TagRepository
13
     */
14
    private $tag;
15
16
    public function __construct(TagRepository $tag)
17
    {
18
        parent::__construct();
19
20
        $this->tag = $tag;
21
    }
22
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @return Response
27
     */
28
    public function index()
29
    {
30
        $tags = $this->tag->all();
31
32
        return view('blog::admin.tags.index', compact('tags'));
33
    }
34
35
    /**
36
     * Show the form for creating a new resource.
37
     *
38
     * @return Response
39
     */
40
    public function create()
41
    {
42
        return view('blog::admin.tags.create');
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param  Request $request
49
     * @return Response
50
     */
51 View Code Duplication
    public function store(Request $request)
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...
52
    {
53
        $this->tag->create($request->all());
54
55
        flash()->success(trans('core::core.messages.resource created', ['name' => trans('blog::tag.title.tag')]));
56
57
        return redirect()->route('admin.blog.tag.index');
58
    }
59
60
    /**
61
     * Show the form for editing the specified resource.
62
     *
63
     * @param  Tag $tag
64
     * @return Response
65
     */
66
    public function edit(Tag $tag)
67
    {
68
        return view('blog::admin.tags.edit', compact('tag'));
69
    }
70
71
    /**
72
     * Update the specified resource in storage.
73
     *
74
     * @param  Tag $tag
75
     * @param  Request $request
76
     * @return Response
77
     */
78 View Code Duplication
    public function update(Tag $tag, Request $request)
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...
79
    {
80
        $this->tag->update($tag, $request->all());
81
82
        flash()->success(trans('core::core.messages.resource updated', ['name' => trans('blog::tag.title.tag')]));
83
84
        return redirect()->route('admin.blog.tag.index');
85
    }
86
87
    /**
88
     * Remove the specified resource from storage.
89
     *
90
     * @param  Tag $tag
91
     * @return Response
92
     */
93 View Code Duplication
    public function destroy(Tag $tag)
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...
94
    {
95
        $this->tag->destroy($tag);
96
97
        flash()->success(trans('core::core.messages.resource deleted', ['name' => trans('blog::tag.title.tag')]));
98
99
        return redirect()->route('admin.blog.tag.index');
100
    }
101
}
102