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

HomeTrait::getSideMenu()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 56

Duplication

Lines 4
Ratio 7.14 %

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 4
loc 56
rs 8.9599
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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