Completed
Pull Request — master (#82)
by Phecho
03:34
created

DashboardController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 79
Duplicated Lines 58.23 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 1
dl 46
loc 79
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 46 46 1
A indexAction() 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
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\Admin;
13
14
use Gitamin\Models\Project;
15
use Illuminate\Routing\Controller;
16
use Illuminate\Support\Facades\Session;
17
use Illuminate\Support\Facades\View;
18
19
class DashboardController extends Controller
20
{
21
    /**
22
     * Creates a new settings controller instance.
23
     *
24
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
     */
26 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...
27
    {
28
        $this->subMenu = [
0 ignored issues
show
Bug introduced by
The property subMenu does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
            'overview' => [
30
                'title'  => 'Overview',
31
                'url'    => route('admin.index'),
32
                'icon'   => 'fa fa-wrench',
33
                'active' => false,
34
            ],
35
            'general' => [
36
                'title'  => trans('admin.settings.general.general'),
37
                'url'    => route('admin.settings.general'),
38
                'icon'   => 'fa fa-gear',
39
                'active' => false,
40
            ],
41
            'theme' => [
42
                'title'  => trans('admin.settings.theme.theme'),
43
                'url'    => route('admin.settings.theme'),
44
                'icon'   => 'fa fa-list-alt',
45
                'active' => false,
46
            ],
47
            'stylesheet' => [
48
                'title'  => trans('admin.settings.stylesheet.stylesheet'),
49
                'url'    => route('admin.settings.stylesheet'),
50
                'icon'   => 'fa fa-magic',
51
                'active' => false,
52
            ],
53
            'localization' => [
54
                'title'  => trans('admin.settings.localization.localization'),
55
                'url'    => route('admin.settings.localization'),
56
                'icon'   => 'fa fa-language',
57
                'active' => false,
58
            ],
59
            'timezone' => [
60
                'title'  => trans('admin.settings.timezone.timezone'),
61
                'url'    => route('admin.settings.timezone'),
62
                'icon'   => 'fa fa-calendar',
63
                'active' => false,
64
            ],
65
        ];
66
67
        View::share([
68
            'sub_title' => trans('admin.admin'),
69
            'sub_menu'  => $this->subMenu,
70
        ]);
71
    }
72
73
    /**
74
     * Display a listing of the resource.
75
     *
76
     * @return \Illuminate\Http\Response
77
     */
78
    public function indexAction()
79
    {
80
        $this->subMenu['overview']['active'] = true;
81
82
        Session::flash('redirect_to', $this->subMenu['general']['url']);
83
84
        $projects = Project::orderBy('created_at')->get();
0 ignored issues
show
Unused Code introduced by
$projects 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...
85
86
        $projects = Project::get();
87
        $issues = [];
88
        $subscribers = [];
89
90
        return View::make('admin.index')
91
            ->withPageTitle(trans('admin.admin'))
92
            ->withProjects($projects)
93
            ->withIssues($issues)
94
            ->withSubscribers($subscribers)
95
            ->withSubMenu($this->subMenu);
96
    }
97
}
98