ProjectsController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 50.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 3
c 4
b 1
f 2
lcom 1
cbo 2
dl 38
loc 75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 28 28 1
A indexAction() 10 10 1
A starredAction() 0 10 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
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers\Dashboard;
13
14
use Gitamin\Models\Project;
15
use Illuminate\Foundation\Bus\DispatchesJobs;
16
use Illuminate\Routing\Controller;
17
use Illuminate\Support\Facades\View;
18
19
class ProjectsController extends Controller
20
{
21
    use DispatchesJobs;
22
23
    /**
24
     * Array of sub-menu items.
25
     *
26
     * @var array
27
     */
28
    protected $subMenu = [];
29
30
    /**
31
     * Creates a new project controller instance.
32
     */
33 View Code Duplication
    public function __construct()
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...
34
    {
35
        $this->subMenu = [
36
            'yours' => [
37
                'title' => trans('dashboard.projects.yours'),
38
                'url' => route('dashboard.projects.index'),
39
                'icon' => 'fa fa-edit',
40
                'active' => false,
41
            ],
42
            'starred' => [
43
                'title' => trans('dashboard.projects.starred'),
44
                'url' => route('dashboard.projects.starred'),
45
                'icon' => 'fa fa-umbrella',
46
                'active' => false,
47
            ],
48
            'explore' => [
49
                'title' => trans('dashboard.projects.explore'),
50
                'url' => route('explore.index'),
51
                'icon' => 'fa fa-eye',
52
                'active' => false,
53
            ],
54
        ];
55
56
        View::share([
57
            'sub_menu' => $this->subMenu,
58
            'sub_title' => trans_choice('dashboard.projects.projects', 2),
59
        ]);
60
    }
61
62
    /**
63
     * Shows the projects view.
64
     *
65
     * @return \Illuminate\View\View
66
     */
67 View Code Duplication
    public function indexAction()
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...
68
    {
69
        $projects = Project::orderBy('created_at')->get();
70
        $this->subMenu['yours']['active'] = true;
71
72
        return View::make('dashboard.projects.index')
73
            ->withPageTitle(trans_choice('dashboard.projects.projects', 2).' - '.trans('dashboard.dashboard'))
74
            ->withProjects($projects)
75
            ->withSubMenu($this->subMenu);
76
    }
77
78
    /**
79
     * Shows the starred projects view.
80
     *
81
     * @return \Illuminate\View\View
82
     */
83
    public function starredAction()
84
    {
85
        $this->subMenu['starred']['active'] = true;
86
        $projects = Project::orderBy('created_at')->get();
87
88
        return View::make('dashboard.projects.index')
89
            ->withPageTitle(trans_choice('dashboard.projects.projects', 2).' - '.trans('dashboard.dashboard'))
90
            ->withProjects($projects)
91
            ->withSubMenu($this->subMenu);
92
    }
93
}
94