Completed
Branch master (8e0976)
by Adam
04:13
created

HomeTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 6.78 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 4
loc 59
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getSideMenu() 4 56 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
2
3
namespace Coyote\Http\Controllers\User;
4
5
use Lavary\Menu\Menu;
6
7
trait HomeTrait
8
{
9
    public function getSideMenu()
10
    {
11
        $collection = [
12
            [
13
                'id' => 'btn-start',
14
                'route' => 'user.home',
15
                'icon' => 'fa-map-marker',
16
                'label' => 'Start'
17
            ],
18
            [
19
                'id' => 'btn-notifies',
20
                'route' => 'user.notifications',
21
                'icon' => 'fa-bell-o',
22
                'label' => 'Powiadomienia'
23
            ],
24
            [
25
                'id' => 'btn-pm',
26
                'route' => 'user.pm',
27
                'icon' => 'fa-envelope-o',
28
                'label' => 'Wiadomości prywatne'
29
            ],
30
            [
31
                'id' => 'btn-favorites',
32
                'route' => 'user.favorites',
33
                'icon' => 'fa-heart',
34
                'label' => 'Ulubione i obserwowane strony'
35
            ],
36
            [
37
                'id' => 'btn-rates',
38
                'route' => 'user.rates',
39
                'icon' => 'fa-star-half',
40
                'label' => 'Oceny moich postów'
41
            ],
42
            [
43
                'id' => 'btn-stats',
44
                'route' => 'user.stats',
45
                'icon' => 'fa-area-chart',
46
                'label' => 'Statystyki moich postów'
47
            ],
48
            [
49
                'id' => 'btn-accepts',
50
                'route' => 'user.accepts',
51
                'icon' => 'fa-check',
52
                'label' => 'Zaakceptowane odpowiedzi'
53
            ]
54
        ];
55
56
        return app(Menu::class)->make('user.home', function ($menu) use ($collection) {
57 View Code Duplication
            foreach ($collection as $row) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
58
                $menu->add($row['label'], ['route' => $row['route'], 'id' => $row['id']])
59
                        ->prepend('<i class="fa fa-fw ' . $row['icon'] . '"></i>');
60
            }
61
62
            $menu->find('btn-pm')->append(' <small>(' . auth()->user()->pm_unread . '/' . auth()->user()->pm . ')</small>');
63
        });
64
    }
65
}
66