SelectItem::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Mvc\View\Components;
26
27
/**
28
 * Class SelectItem
29
 *
30
 * @package SP\Mvc\View\Components
31
 */
32
final class SelectItem
33
{
34
    /**
35
     * @var int
36
     */
37
    protected $id;
38
    /**
39
     * @var string
40
     */
41
    protected $name;
42
    /**
43
     * @var mixed
44
     */
45
    protected $item;
46
    /**
47
     * @var bool
48
     */
49
    protected $selected = false;
50
    /**
51
     * @var bool
52
     */
53
    protected $skip = false;
54
55
    /**
56
     * SelectItem constructor.
57
     *
58
     * @param int    $id
59
     * @param string $name
60
     * @param null   $item
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $item is correct as it would always require null to be passed?
Loading history...
61
     */
62
    public function __construct($id, $name, $item = null)
63
    {
64
        $this->id = is_numeric($id) ? (int)$id : $id;
0 ignored issues
show
introduced by
The condition is_numeric($id) is always true.
Loading history...
65
        $this->name = (string)$name;
66
        $this->item = $item;
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function getId()
73
    {
74
        return $this->id;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getName()
81
    {
82
        return $this->name;
83
    }
84
85
    /**
86
     * @return bool
87
     */
88
    public function isSelected()
89
    {
90
        return $this->selected;
91
    }
92
93
    /**
94
     * @param bool $selected
95
     */
96
    public function setSelected($selected)
97
    {
98
        $this->selected = (bool)$selected;
99
    }
100
101
    /**
102
     * @param $property
103
     *
104
     * @return mixed
105
     */
106
    public function getItemProperty($property)
107
    {
108
        return null !== $this->item && isset($this->item->{$property}) ? $this->item->{$property} : null;
109
    }
110
111
    /**
112
     * @return bool
113
     */
114
    public function isSkip()
115
    {
116
        return $this->skip;
117
    }
118
119
    /**
120
     * @param bool $skip
121
     */
122
    public function setSkip($skip)
123
    {
124
        $this->skip = (bool)$skip;
125
    }
126
}