Passed
Push — devel-3.0 ( 5f7f30...cd1038 )
by Rubén
03:44
created

AccountDefaultPermissionData::getPermission()   A

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-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\Util\Util;
28
29
/**
30
 * Class AccountDefaultPermission
31
 *
32
 * @package SP\DataModel
33
 */
34
class AccountDefaultPermissionData extends DataModelBase
35
{
36
    /**
37
     * @var int
38
     */
39
    public $id;
40
    /**
41
     * @var int
42
     */
43
    public $userId;
44
    /**
45
     * @var int
46
     */
47
    public $userGroupId;
48
    /**
49
     * @var int
50
     */
51
    public $userProfileId;
52
    /**
53
     * @var int
54
     */
55
    public $fixed;
56
    /**
57
     * @var int
58
     */
59
    public $priority;
60
    /**
61
     * @var string
62
     */
63
    public $permission;
64
    /**
65
     * @var AccountPermission
66
     */
67
    private $accountPermission;
68
69
    /**
70
     * @return int
71
     */
72
    public function getId(): int
73
    {
74
        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...
75
    }
76
77
    /**
78
     * @param int $id
79
     *
80
     * @return AccountDefaultPermissionData
81
     */
82
    public function setId(int $id)
83
    {
84
        $this->id = $id;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function getUserId()
93
    {
94
        return $this->userId !== null ? (int)$this->userId : null;
95
    }
96
97
    /**
98
     * @param int $userId
99
     *
100
     * @return AccountDefaultPermissionData
101
     */
102
    public function setUserId(int $userId)
103
    {
104
        $this->userId = $userId;
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return int
111
     */
112
    public function getUserGroupId()
113
    {
114
        return $this->userGroupId !== null ? (int)$this->userGroupId : null;
115
    }
116
117
    /**
118
     * @param int $userGroupId
119
     *
120
     * @return AccountDefaultPermissionData
121
     */
122
    public function setUserGroupId(int $userGroupId)
123
    {
124
        $this->userGroupId = $userGroupId;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return int
131
     */
132
    public function getUserProfileId()
133
    {
134
        return $this->userProfileId !== null ? (int)$this->userProfileId : null;
135
    }
136
137
    /**
138
     * @param int $userProfileId
139
     *
140
     * @return AccountDefaultPermissionData
141
     */
142
    public function setUserProfileId(int $userProfileId)
143
    {
144
        $this->userProfileId = $userProfileId;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @return int
151
     */
152
    public function getFixed(): int
153
    {
154
        return (int)$this->fixed;
155
    }
156
157
    /**
158
     * @param int $fixed
159
     *
160
     * @return AccountDefaultPermissionData
161
     */
162
    public function setFixed(int $fixed)
163
    {
164
        $this->fixed = $fixed;
165
166
        return $this;
167
    }
168
169
    /**
170
     * @return int
171
     */
172
    public function getPriority(): int
173
    {
174
        return (int)$this->priority;
175
    }
176
177
    /**
178
     * @param int $priority
179
     *
180
     * @return AccountDefaultPermissionData
181
     */
182
    public function setPriority(int $priority)
183
    {
184
        $this->priority = $priority;
185
186
        return $this;
187
    }
188
189
    /**
190
     * @return string
191
     */
192
    public function getPermission()
193
    {
194
        return $this->permission;
195
    }
196
197
    /**
198
     * @return string
199
     */
200
    public function getHash()
201
    {
202
        return sha1((int)$this->userId . (int)$this->userGroupId . (int)$this->userProfileId . (int)$this->priority);
203
    }
204
205
    /**
206
     * @return $this
207
     */
208
    public function hydrate()
209
    {
210
        if ($this->permission !== null) {
211
            $this->accountPermission = Util::unserialize(AccountPermission::class, $this->permission);
0 ignored issues
show
Documentation Bug introduced by
It seems like SP\Util\Util::unserializ...ass, $this->permission) can also be of type string. However, the property $accountPermission is declared as type SP\DataModel\AccountPermission. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
212
        }
213
214
        return $this;
215
    }
216
217
    /**
218
     * @return AccountPermission
219
     */
220
    public function getAccountPermission()
221
    {
222
        return $this->accountPermission;
223
    }
224
225
    /**
226
     * @param AccountPermission $accountPermission
227
     *
228
     * @return AccountDefaultPermissionData
229
     */
230
    public function setAccountPermission(AccountPermission $accountPermission)
231
    {
232
        $this->accountPermission = $accountPermission;
233
        $this->permission = serialize($accountPermission);
234
235
        return $this;
236
    }
237
}