Completed
Push — master ( 7bb44a...72105c )
by Laurent
02:19
created

TabCollection::addTab()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 */
5
6
/**
7
 * TabCollection class
8
 *
9
 * @author Laurent De Coninck <[email protected]>
10
 */
11
class TabCollection implements \Countable
12
{
13
14
    /**
15
     * @var Tab[]
16
     */
17
    private $tabs;
18
19
    /**
20
     * TabCollection constructor.
21
     *
22
     * @param Tab[] $tabs
23
     */
24
    public function __construct(array $tabs = [])
25
    {
26
        $this->tabs = $tabs;
27
    }
28
29
    /**
30
     * Count elements of an object
31
     * @link  http://php.net/manual/en/countable.count.php
32
     * @return int The custom count as an integer.
33
     * </p>
34
     * <p>
35
     * The return value is cast to an integer.
36
     * @since 5.1.0
37
     */
38
    public function count()
39
    {
40
        return count($this->tabs);
41
    }
42
43
    /**
44
     * @param Tab $tab
45
     *
46
     * @return TabCollection
47
     */
48
    public function addTab(Tab $tab){
49
        $this->tabs[] = $tab;
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function toArray(){
56
        $tabAsArray = [];
57
58
        foreach ($this->tabs as $tab){
59
            $tabAsArray[] = $tab->toArray();
60
        }
61
62
        return $tabAsArray;
63
    }
64
}