NavigationOrdener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A order() 0 18 3
A getItem() 0 4 2
1
<?php namespace Modules\Core\Navigation;
2
3
use Illuminate\Support\Collection;
4
5
class NavigationOrdener
6
{
7
    public static function order(Collection $items)
8
    {
9
        return $items->sort(
10
            function ($item1, $item2) {
11
                $item1 = self::getItem($item1);
12
                $item2 = self::getItem($item2);
13
14
                if ($item1['weight'] > $item2['weight']) {
15
                    return 1;
16
                }
17
                if ($item1['weight'] < $item2['weight']) {
18
                    return -1;
19
                }
20
21
                return 0;
22
            }
23
        );
24
    }
25
26
    /**
27
     * @param $item
28
     * @return mixed
29
     */
30
    public static function getItem($item)
31
    {
32
        return isset($item['weight']) ? $item : $item->first();
33
    }
34
}
35