Collection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 78
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A addItems() 0 8 2
A addItem() 0 4 1
A setSelected() 0 6 1
A hasAnySelected() 0 6 1
1
<?php namespace Arcanesoft\Sidebar;
2
3
use Illuminate\Support\Collection as BaseCollection;
4
5
/**
6
 * Class     Collection
7
 *
8
 * @package  Arcanesoft\Sidebar
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class Collection extends BaseCollection
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Add a sidebar item.
20
     *
21
     * @param  \Arcanesoft\Sidebar\Item  $item
22
     *
23
     * @return $this
24
     */
25 28
    public function add(Item $item)
26
    {
27 28
        return $this->push($item);
28
    }
29
30
    /**
31
     * Push multiple sidebar items into the collection.
32
     *
33
     * @param  array  $items
34
     *
35
     * @return $this
36
     */
37 56
    public function addItems(array $items)
38
    {
39 56
        foreach ($items as $item) {
40 16
            $this->addItem($item);
41
        }
42
43 56
        return $this;
44
    }
45
46
    /**
47
     * Push a new sidebar item to the collection.
48
     *
49
     * @param  array  $attributes
50
     *
51
     * @return $this
52
     */
53 28
    public function addItem(array $attributes)
54
    {
55 28
        return $this->add(new Item($attributes));
56
    }
57
58
    /**
59
     * Set the selected item.
60
     *
61
     * @param  string  $name
62
     *
63
     * @return $this
64
     */
65 12
    public function setSelected(string $name)
66
    {
67
        return $this->transform(function (Item $item) use ($name) {
68 8
            return $item->setSelected($name);
69 12
        });
70
    }
71
72
    /* -----------------------------------------------------------------
73
     |  Check Methods
74
     | -----------------------------------------------------------------
75
     */
76
77
    /**
78
     * Check if there is any item selected.
79
     *
80
     * @return bool
81
     */
82 16
    public function hasAnySelected() : bool
83
    {
84
        return $this->filter(function (Item $item) {
85 12
            return $item->isActive();
86 16
        })->isNotEmpty();
87
    }
88
}
89