Passed
Push — devel-3.0 ( 7ceb3a...2fc71e )
by Rubén
03:58
created

ItemPresetData::setUserProfileId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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-2018, 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\DataModel;
26
27
use SP\Core\Exceptions\NoSuchPropertyException;
28
use SP\Util\Util;
29
30
/**
31
 * Class ItemPresetData
32
 *
33
 * @package SP\DataModel
34
 */
35
class ItemPresetData extends DataModelBase implements HydratableInterface
36
{
37
    /**
38
     * @var int
39
     */
40
    public $id;
41
    /**
42
     * @var string
43
     */
44
    public $type;
45
    /**
46
     * @var int
47
     */
48
    public $userId;
49
    /**
50
     * @var int
51
     */
52
    public $userGroupId;
53
    /**
54
     * @var int
55
     */
56
    public $userProfileId;
57
    /**
58
     * @var int
59
     */
60
    public $fixed;
61
    /**
62
     * @var int
63
     */
64
    public $priority;
65
    /**
66
     * @var string
67
     */
68
    public $data;
69
70
    /**
71
     * @return int
72
     */
73
    public function getId(): int
74
    {
75
        return $this->id !== null ? (int)$this->id : null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->id !== null ? (int)$this->id : null could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
76
    }
77
78
    /**
79
     * @param int $id
80
     *
81
     * @return ItemPresetData
82
     */
83
    public function setId(int $id)
84
    {
85
        $this->id = $id;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @return int
92
     */
93
    public function getUserId()
94
    {
95
        return $this->userId !== null ? (int)$this->userId : null;
96
    }
97
98
    /**
99
     * @param int $userId
100
     *
101
     * @return ItemPresetData
102
     */
103
    public function setUserId(int $userId)
104
    {
105
        $this->userId = $userId;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getUserGroupId()
114
    {
115
        return $this->userGroupId !== null ? (int)$this->userGroupId : null;
116
    }
117
118
    /**
119
     * @param int $userGroupId
120
     *
121
     * @return ItemPresetData
122
     */
123
    public function setUserGroupId(int $userGroupId)
124
    {
125
        $this->userGroupId = $userGroupId;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return int
132
     */
133
    public function getUserProfileId()
134
    {
135
        return $this->userProfileId !== null ? (int)$this->userProfileId : null;
136
    }
137
138
    /**
139
     * @param int $userProfileId
140
     *
141
     * @return ItemPresetData
142
     */
143
    public function setUserProfileId(int $userProfileId)
144
    {
145
        $this->userProfileId = $userProfileId;
146
147
        return $this;
148
    }
149
150
    /**
151
     * @return int
152
     */
153
    public function getFixed(): int
154
    {
155
        return (int)$this->fixed;
156
    }
157
158
    /**
159
     * @param int $fixed
160
     *
161
     * @return ItemPresetData
162
     */
163
    public function setFixed(int $fixed)
164
    {
165
        $this->fixed = $fixed;
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return int
172
     */
173
    public function getPriority(): int
174
    {
175
        return (int)$this->priority;
176
    }
177
178
    /**
179
     * @param int $priority
180
     *
181
     * @return ItemPresetData
182
     */
183
    public function setPriority(int $priority)
184
    {
185
        $this->priority = $priority;
186
187
        return $this;
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getData()
194
    {
195
        return $this->data;
196
    }
197
198
    /**
199
     * @param string $data
200
     */
201
    public function setData(string $data)
202
    {
203
        $this->data = $data;
204
    }
205
206
    /**
207
     * @return string
208
     */
209
    public function getHash()
210
    {
211
        return sha1($this->type . (int)$this->userId . (int)$this->userGroupId . (int)$this->userProfileId . (int)$this->priority);
212
    }
213
214
    /**
215
     * @param string $class
216
     *
217
     * @param string $property
218
     *
219
     * @return mixed
220
     * @throws NoSuchPropertyException
221
     */
222
    public function hydrate(string $class = null, string $property = 'data')
223
    {
224
        if (property_exists($this, $property)) {
225
            if ($this->data !== null) {
226
                return $class !== null ? Util::unserialize($class, $this->data) : unserialize($this->data);
227
            }
228
229
            return null;
230
        }
231
232
        throw new NoSuchPropertyException($property);
233
    }
234
235
    /**
236
     * @return string
237
     */
238
    public function getType()
239
    {
240
        return $this->type;
241
    }
242
243
    /**
244
     * @param string $type
245
     */
246
    public function setType(string $type)
247
    {
248
        $this->type = $type;
249
    }
250
}