Completed
Pull Request — master (#358)
by
unknown
06:38
created

NavigationCollection::home()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 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
class NavigationCollection extends Collection
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
    /**
53
     * Get landing page
54
     *
55
     * @return NavigationLink
56
     */
57
    public function home()
58
    {
59
        return $this->get('anomaly.module.dashboard');
60
    }
61
}
62