44
55use BookStack \Access \RegistrationService ;
66use Illuminate \Auth \GuardHelpers ;
7- use Illuminate \Contracts \Auth \Authenticatable as AuthenticatableContract ;
7+ use Illuminate \Contracts \Auth \Authenticatable ;
88use Illuminate \Contracts \Auth \StatefulGuard ;
99use Illuminate \Contracts \Auth \UserProvider ;
1010use Illuminate \Contracts \Session \Session ;
@@ -24,43 +24,31 @@ class ExternalBaseSessionGuard implements StatefulGuard
2424 * The name of the Guard. Typically "session".
2525 *
2626 * Corresponds to guard name in authentication configuration.
27- *
28- * @var string
2927 */
30- protected $ name ;
28+ protected readonly string $ name ;
3129
3230 /**
3331 * The user we last attempted to retrieve.
34- *
35- * @var \Illuminate\Contracts\Auth\Authenticatable
3632 */
37- protected $ lastAttempted ;
33+ protected Authenticatable $ lastAttempted ;
3834
3935 /**
4036 * The session used by the guard.
41- *
42- * @var \Illuminate\Contracts\Session\Session
4337 */
44- protected $ session ;
38+ protected Session $ session ;
4539
4640 /**
4741 * Indicates if the logout method has been called.
48- *
49- * @var bool
5042 */
51- protected $ loggedOut = false ;
43+ protected bool $ loggedOut = false ;
5244
5345 /**
5446 * Service to handle common registration actions.
55- *
56- * @var RegistrationService
5747 */
58- protected $ registrationService ;
48+ protected RegistrationService $ registrationService ;
5949
6050 /**
6151 * Create a new authentication guard.
62- *
63- * @return void
6452 */
6553 public function __construct (string $ name , UserProvider $ provider , Session $ session , RegistrationService $ registrationService )
6654 {
@@ -72,13 +60,11 @@ public function __construct(string $name, UserProvider $provider, Session $sessi
7260
7361 /**
7462 * Get the currently authenticated user.
75- *
76- * @return \Illuminate\Contracts\Auth\Authenticatable|null
7763 */
78- public function user ()
64+ public function user (): Authenticatable | null
7965 {
8066 if ($ this ->loggedOut ) {
81- return ;
67+ return null ;
8268 }
8369
8470 // If we've already retrieved the user for the current request we can just
@@ -101,13 +87,11 @@ public function user()
10187
10288 /**
10389 * Get the ID for the currently authenticated user.
104- *
105- * @return int|null
10690 */
107- public function id ()
91+ public function id (): int | null
10892 {
10993 if ($ this ->loggedOut ) {
110- return ;
94+ return null ;
11195 }
11296
11397 return $ this ->user ()
@@ -117,12 +101,8 @@ public function id()
117101
118102 /**
119103 * Log a user into the application without sessions or cookies.
120- *
121- * @param array $credentials
122- *
123- * @return bool
124104 */
125- public function once (array $ credentials = [])
105+ public function once (array $ credentials = []): bool
126106 {
127107 if ($ this ->validate ($ credentials )) {
128108 $ this ->setUser ($ this ->lastAttempted );
@@ -135,12 +115,8 @@ public function once(array $credentials = [])
135115
136116 /**
137117 * Log the given user ID into the application without sessions or cookies.
138- *
139- * @param mixed $id
140- *
141- * @return \Illuminate\Contracts\Auth\Authenticatable|false
142118 */
143- public function onceUsingId ($ id )
119+ public function onceUsingId ($ id ): Authenticatable | false
144120 {
145121 if (!is_null ($ user = $ this ->provider ->retrieveById ($ id ))) {
146122 $ this ->setUser ($ user );
@@ -153,38 +129,26 @@ public function onceUsingId($id)
153129
154130 /**
155131 * Validate a user's credentials.
156- *
157- * @param array $credentials
158- *
159- * @return bool
160132 */
161- public function validate (array $ credentials = [])
133+ public function validate (array $ credentials = []): bool
162134 {
163135 return false ;
164136 }
165137
166138 /**
167139 * Attempt to authenticate a user using the given credentials.
168- *
169- * @param array $credentials
170- * @param bool $remember
171- *
172- * @return bool
140+ * @param bool $remember
173141 */
174- public function attempt (array $ credentials = [], $ remember = false )
142+ public function attempt (array $ credentials = [], $ remember = false ): bool
175143 {
176144 return false ;
177145 }
178146
179147 /**
180148 * Log the given user ID into the application.
181- *
182- * @param mixed $id
183149 * @param bool $remember
184- *
185- * @return \Illuminate\Contracts\Auth\Authenticatable|false
186150 */
187- public function loginUsingId ($ id , $ remember = false )
151+ public function loginUsingId (mixed $ id , $ remember = false ): Authenticatable | false
188152 {
189153 // Always return false as to disable this method,
190154 // Logins should route through LoginService.
@@ -194,12 +158,9 @@ public function loginUsingId($id, $remember = false)
194158 /**
195159 * Log a user into the application.
196160 *
197- * @param \Illuminate\Contracts\Auth\Authenticatable $user
198- * @param bool $remember
199- *
200- * @return void
161+ * @param bool $remember
201162 */
202- public function login (AuthenticatableContract $ user , $ remember = false )
163+ public function login (Authenticatable $ user , $ remember = false ): void
203164 {
204165 $ this ->updateSession ($ user ->getAuthIdentifier ());
205166
@@ -208,12 +169,8 @@ public function login(AuthenticatableContract $user, $remember = false)
208169
209170 /**
210171 * Update the session with the given ID.
211- *
212- * @param string $id
213- *
214- * @return void
215172 */
216- protected function updateSession ($ id )
173+ protected function updateSession (string | int $ id ): void
217174 {
218175 $ this ->session ->put ($ this ->getName (), $ id );
219176
@@ -222,10 +179,8 @@ protected function updateSession($id)
222179
223180 /**
224181 * Log the user out of the application.
225- *
226- * @return void
227182 */
228- public function logout ()
183+ public function logout (): void
229184 {
230185 $ this ->clearUserDataFromStorage ();
231186
@@ -239,62 +194,48 @@ public function logout()
239194
240195 /**
241196 * Remove the user data from the session and cookies.
242- *
243- * @return void
244197 */
245- protected function clearUserDataFromStorage ()
198+ protected function clearUserDataFromStorage (): void
246199 {
247200 $ this ->session ->remove ($ this ->getName ());
248201 }
249202
250203 /**
251204 * Get the last user we attempted to authenticate.
252- *
253- * @return \Illuminate\Contracts\Auth\Authenticatable
254205 */
255- public function getLastAttempted ()
206+ public function getLastAttempted (): Authenticatable
256207 {
257208 return $ this ->lastAttempted ;
258209 }
259210
260211 /**
261212 * Get a unique identifier for the auth session value.
262- *
263- * @return string
264213 */
265- public function getName ()
214+ public function getName (): string
266215 {
267216 return 'login_ ' . $ this ->name . '_ ' . sha1 (static ::class);
268217 }
269218
270219 /**
271220 * Determine if the user was authenticated via "remember me" cookie.
272- *
273- * @return bool
274221 */
275- public function viaRemember ()
222+ public function viaRemember (): bool
276223 {
277224 return false ;
278225 }
279226
280227 /**
281228 * Return the currently cached user.
282- *
283- * @return \Illuminate\Contracts\Auth\Authenticatable|null
284229 */
285- public function getUser ()
230+ public function getUser (): Authenticatable | null
286231 {
287232 return $ this ->user ;
288233 }
289234
290235 /**
291236 * Set the current user.
292- *
293- * @param \Illuminate\Contracts\Auth\Authenticatable $user
294- *
295- * @return $this
296237 */
297- public function setUser (AuthenticatableContract $ user )
238+ public function setUser (Authenticatable $ user ): self
298239 {
299240 $ this ->user = $ user ;
300241
0 commit comments