Completed
Pull Request — master (#3)
by ARCANEDEV
05:33
created

SidebarCollection::pushSidebarItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
nc 1
nop 1
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php namespace Arcanesoft\Sidebar;
2
3
use Illuminate\Support\Collection;
4
5
/**
6
 * Class     SidebarCollection
7
 *
8
 * @package  Arcanesoft\Sidebar
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class SidebarCollection extends Collection
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Push multiple sidebar items into the collection.
20
     *
21
     * @param  array  $items
22
     *
23
     * @return $this
24
     */
25 16
    public function pushSidebarItems(array $items)
26
    {
27 16
        foreach ($items as $item) {
28 12
            $this->pushSidebarItem($item);
29
        }
30
31 16
        return $this;
32
    }
33
34
    /**
35
     * Push a new sidebar item to the collection.
36
     *
37
     * @param  array  $attributes
38
     *
39
     * @return $this
40
     */
41 16
    public function pushSidebarItem(array $attributes)
42
    {
43 16
        return $this->push(new SidebarItem($attributes));
44
    }
45
46
    /**
47
     * Set the selected item.
48
     *
49
     * @param  string  $name
50
     *
51
     * @return $this
52
     */
53 4
    public function setSelected(string $name)
54
    {
55
        return $this->transform(function (SidebarItem $item) use ($name) {
56 4
            return $item->setSelected($name);
57 4
        });
58
    }
59
60
    /**
61
     * Check if there is any item selected.
62
     *
63
     * @return bool
64
     */
65 12
    public function hasAnySelected() : bool
66
    {
67
        return $this->filter(function (SidebarItem $item) {
68 8
            return $item->isActive();
69 12
        })->isNotEmpty();
70
    }
71
}
72