Completed
Push — master ( a0253d...70910a )
by Ryan
12:32 queued 06:51
created

NavigationCollection::main()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 7
nc 3
nop 0
1
<?php namespace Anomaly\Streams\Platform\Ui\ControlPanel\Component\Navigation;
2
3
use Anomaly\Streams\Platform\Support\Collection;
4
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Navigation\Contract\NavigationLinkInterface;
5
6
/**
7
 * Class NavigationCollection
8
 *
9
 * @link   http://pyrocms.com/
10
 * @author PyroCMS, Inc. <[email protected]>
11
 * @author Ryan Thompson <[email protected]>
12
 */
13 View Code Duplication
class NavigationCollection extends Collection
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
16
    /**
17
     * Return the active link.
18
     *
19
     * @return null|NavigationLinkInterface
20
     */
21
    public function active()
22
    {
23
        /* @var NavigationLinkInterface $item */
24
        foreach ($this->items as $item) {
25
            if ($item->isActive()) {
26
                return $item;
27
            }
28
        }
29
30
        return null;
31
    }
32
33
    /**
34
     * Get a navigation link.
35
     *
36
     * @param  mixed $key
37
     * @param  null  $default
38
     * @return NavigationLinkInterface
39
     */
40
    public function get($key, $default = null)
41
    {
42
        /* @var NavigationLinkInterface $item */
43
        foreach ($this->items as $item) {
44
            if ($item->getSlug() == $key) {
45
                return $item;
46
            }
47
        }
48
49
        return $default ? $this->get($default) : null;
50
    }
51
}
52