Completed
Push — 1.x ( 8c441f...0f5ece )
by Asao
02:43
created

NavBar::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
namespace Tuum\Form\Components;
3
4
class NavBar
5
{
6
    /**
7
     * @var string[]
8
     */
9
    private $current = [];
10
11
    /**
12
     * @var string[]
13
     */
14
    private $items;
15
16
    public $onItem = ' active';
17
18
    public $offItem = '';
19
20
    /**
21
     * NavBar constructor.
22
     *
23
     * @param string $menu1
24
     */
25
    public function __construct($menu1)
0 ignored issues
show
Unused Code introduced by
The parameter $menu1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        $this->current = func_get_args();
28
    }
29
30
    /**
31
     * @param string $menu1
32
     * @return NavBar
33
     */
34
    public function m($menu1)
0 ignored issues
show
Unused Code introduced by
The parameter $menu1 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        $self = clone($this);
37
        $self->items = func_get_args();
38
39
        return $self;
40
    }
41
42
    /**
43
     * @param string $string
44
     * @return $this
45
     */
46
    public function on($string)
47
    {
48
        $this->onItem = $string;
49
        return $this;
50
    }
51
52
    /**
53
     * @param string $string
54
     * @return $this
55
     */
56
    public function off($string)
57
    {
58
        $this->offItem = $string;
59
        return $this;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function is()
66
    {
67
        foreach($this->items as $key => $item) {
68
            if (!array_key_exists($key, $this->current) ||
69
                $this->current[$key] !== $item) {
70
                return false;
71
            }
72
        }
73
        return true;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function __toString()
80
    {
81
        if ($this->is()) {
82
            return $this->onItem;
83
        }
84
        return $this->offItem;
85
    }
86
}