@@ -61,7 +61,9 @@ |
||
61 | 61 | */ |
62 | 62 | public static function expandGroup($groups) |
63 | 63 | { |
64 | - if (!is_array($groups)) $groups = (array)$groups; |
|
64 | + if (!is_array($groups)) { |
|
65 | + $groups = (array)$groups; |
|
66 | + } |
|
65 | 67 | |
66 | 68 | $expanded = $groups; |
67 | 69 |
@@ -61,7 +61,9 @@ |
||
61 | 61 | public static function getLevel($name) |
62 | 62 | { |
63 | 63 | $levels = static::getLevels(); |
64 | - if (!isset($levels[$name])) throw new \Exception("Authorization level '$name' isn't defined."); |
|
64 | + if (!isset($levels[$name])) { |
|
65 | + throw new \Exception("Authorization level '$name' isn't defined."); |
|
66 | + } |
|
65 | 67 | |
66 | 68 | return $levels[$name]; |
67 | 69 | } |
@@ -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 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | // Black hole |
49 | 49 | trigger_error( |
50 | - "Method for remembering the current user isn't implemented. " . |
|
50 | + "Method for remembering the current user isn't implemented. ". |
|
51 | 51 | "You can use the Jasny\Auth\Sessions trait to store the current user in a session", |
52 | 52 | E_USER_NOTICE |
53 | 53 | ); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param string $password |
71 | 71 | * @param string $salt Use specific salt to verify existing password |
72 | 72 | */ |
73 | - public static function password($password, $salt=null) |
|
73 | + public static function password($password, $salt = null) |
|
74 | 74 | { |
75 | 75 | return isset($salt) ? crypt($password, $salt) : password_hash($password, PASSWORD_BCRYPT); |
76 | 76 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | { |
194 | 194 | $id = is_object($user) ? $user->getId() : $user; |
195 | 195 | |
196 | - return sprintf('%010s', substr(base_convert(md5($id . static::getSecret()), 16, 36), -10) . |
|
196 | + return sprintf('%010s', substr(base_convert(md5($id.static::getSecret()), 16, 36), -10). |
|
197 | 197 | base_convert($id, 10, 36)); |
198 | 198 | } |
199 | 199 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $id = $user->getId(); |
223 | 223 | $password = $user->getPassword(); |
224 | 224 | |
225 | - return sprintf('%010s', substr(base_convert(md5($id . static::getSecret() . $password), 16, 36), -10) |
|
225 | + return sprintf('%010s', substr(base_convert(md5($id.static::getSecret().$password), 16, 36), -10) |
|
226 | 226 | . base_convert($id, 10, 36)); |
227 | 227 | } |
228 | 228 |