@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Get current authenticated user id |
58 | 58 | * |
59 | - * @return mixed |
|
59 | + * @return integer |
|
60 | 60 | */ |
61 | 61 | protected static function getCurrentUserId() |
62 | 62 | { |
@@ -79,7 +79,9 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * Fetch user and verify password |
81 | 81 | * |
82 | - * @return User|false |
|
82 | + * @param string $username |
|
83 | + * @param string $password |
|
84 | + * @return User |
|
83 | 85 | */ |
84 | 86 | public static function verify($username, $password) |
85 | 87 | { |
@@ -94,7 +96,7 @@ discard block |
||
94 | 96 | * |
95 | 97 | * @param string $username |
96 | 98 | * @param string $password |
97 | - * @return boolean |
|
99 | + * @return null|boolean |
|
98 | 100 | */ |
99 | 101 | public static function login($username, $password) |
100 | 102 | { |
@@ -186,7 +188,7 @@ discard block |
||
186 | 188 | /** |
187 | 189 | * Generate a confirmation hash |
188 | 190 | * |
189 | - * @param User|int $user |
|
191 | + * @param string $user |
|
190 | 192 | * @return string |
191 | 193 | */ |
192 | 194 | public static function generateConfirmationHash($user) |
@@ -85,7 +85,9 @@ discard block |
||
85 | 85 | { |
86 | 86 | $user = static::fetchUserByUsername($username); |
87 | 87 | |
88 | - if (!$user || $user->getPassword() !== static::password($password, $user->getPassword())) return false; |
|
88 | + if (!$user || $user->getPassword() !== static::password($password, $user->getPassword())) { |
|
89 | + return false; |
|
90 | + } |
|
89 | 91 | return $user; |
90 | 92 | } |
91 | 93 | |
@@ -99,7 +101,9 @@ discard block |
||
99 | 101 | public static function login($username, $password) |
100 | 102 | { |
101 | 103 | $user = static::verify($username, $password); |
102 | - if (!$user) return null; |
|
104 | + if (!$user) { |
|
105 | + return null; |
|
106 | + } |
|
103 | 107 | |
104 | 108 | return static::setUser($user); |
105 | 109 | } |
@@ -112,7 +116,9 @@ discard block |
||
112 | 116 | */ |
113 | 117 | public static function setUser(User $user) |
114 | 118 | { |
115 | - if ($user->onLogin() === false) return false; |
|
119 | + if ($user->onLogin() === false) { |
|
120 | + return false; |
|
121 | + } |
|
116 | 122 | |
117 | 123 | self::$user = $user; |
118 | 124 | static::persistCurrentUser(); |
@@ -126,7 +132,9 @@ discard block |
||
126 | 132 | public static function logout() |
127 | 133 | { |
128 | 134 | $user = static::user(); |
129 | - if (!$user) return; |
|
135 | + if (!$user) { |
|
136 | + return; |
|
137 | + } |
|
130 | 138 | |
131 | 139 | $user->onLogout(); |
132 | 140 | |
@@ -143,7 +151,9 @@ discard block |
||
143 | 151 | { |
144 | 152 | if (!isset(static::$user)) { |
145 | 153 | $uid = static::getCurrentUserId(); |
146 | - if ($uid) static::$user = static::fetchUserById($uid); |
|
154 | + if ($uid) { |
|
155 | + static::$user = static::fetchUserById($uid); |
|
156 | + } |
|
147 | 157 | } |
148 | 158 | |
149 | 159 | return static::$user; |
@@ -165,8 +175,12 @@ discard block |
||
165 | 175 | */ |
166 | 176 | public static function access($role = null) |
167 | 177 | { |
168 | - if (!static::user()) return false; |
|
169 | - if (!isset($role)) return true; |
|
178 | + if (!static::user()) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + if (!isset($role)) { |
|
182 | + return true; |
|
183 | + } |
|
170 | 184 | |
171 | 185 | return static::user() instanceof Authz\User && static::user()->hasRole($role); |
172 | 186 | } |
@@ -179,7 +193,9 @@ discard block |
||
179 | 193 | */ |
180 | 194 | protected static function getSecret() |
181 | 195 | { |
182 | - if (!isset(static::$secret)) throw new \Exception("Auth secret isn't set"); |
|
196 | + if (!isset(static::$secret)) { |
|
197 | + throw new \Exception("Auth secret isn't set"); |
|
198 | + } |
|
183 | 199 | return static::$secret; |
184 | 200 | } |
185 | 201 | |
@@ -206,7 +222,10 @@ discard block |
||
206 | 222 | public static function fetchForConfirmation($hash) |
207 | 223 | { |
208 | 224 | $id = base_convert(substr($hash, 10), 36, 10); |
209 | - if (static::generateConfirmationHash($id) != $hash) return null; // invalid hash |
|
225 | + if (static::generateConfirmationHash($id) != $hash) { |
|
226 | + return null; |
|
227 | + } |
|
228 | + // invalid hash |
|
210 | 229 | |
211 | 230 | return static::fetchUserById($id); |
212 | 231 | } |
@@ -237,7 +256,10 @@ discard block |
||
237 | 256 | $id = base_convert(substr($hash, 10), 36, 10); |
238 | 257 | |
239 | 258 | $user = static::fetchUserById($id); |
240 | - if (!$user || static::generatePasswordResetHash($user) != $hash) return null; // invalid hash |
|
259 | + if (!$user || static::generatePasswordResetHash($user) != $hash) { |
|
260 | + return null; |
|
261 | + } |
|
262 | + // invalid hash |
|
241 | 263 | |
242 | 264 | return $user; |
243 | 265 | } |