@@ -40,22 +40,16 @@ class AuthenticationService implements AuthenticationServiceInterface, Impersona
4040
4141 /**
4242 * Authenticator collection
43- *
44- * @var \Authentication\Authenticator\AuthenticatorCollection|null
4543 */
4644 protected ?AuthenticatorCollection $ _authenticators = null ;
4745
4846 /**
4947 * Authenticator that successfully authenticated the identity.
50- *
51- * @var \Authentication\Authenticator\AuthenticatorInterface|null
5248 */
5349 protected ?AuthenticatorInterface $ _successfulAuthenticator = null ;
5450
5551 /**
5652 * Result of the last authenticate() call.
57- *
58- * @var \Authentication\Authenticator\ResultInterface|null
5953 */
6054 protected ?ResultInterface $ _result = null ;
6155
@@ -129,7 +123,7 @@ public function __construct(array $config = [])
129123 */
130124 public function authenticators (): AuthenticatorCollection
131125 {
132- if ($ this ->_authenticators === null ) {
126+ if (! $ this ->_authenticators instanceof AuthenticatorCollection ) {
133127 $ authenticators = $ this ->getConfig ('authenticators ' );
134128 $ this ->_authenticators = new AuthenticatorCollection ($ authenticators );
135129 }
@@ -259,7 +253,7 @@ public function getAuthenticationProvider(): ?AuthenticatorInterface
259253 */
260254 public function getIdentificationProvider (): ?IdentifierInterface
261255 {
262- if ($ this ->_successfulAuthenticator === null ) {
256+ if (! $ this ->_successfulAuthenticator instanceof AuthenticatorInterface ) {
263257 return null ;
264258 }
265259
@@ -283,7 +277,7 @@ public function getResult(): ?ResultInterface
283277 */
284278 public function getIdentity (): ?IdentityInterface
285279 {
286- if ($ this ->_result === null ) {
280+ if (! $ this ->_result instanceof ResultInterface ) {
287281 return null ;
288282 }
289283
@@ -319,16 +313,12 @@ public function buildIdentity(ArrayAccess|array $identityData): IdentityInterfac
319313
320314 $ class = $ this ->getConfig ('identityClass ' );
321315
322- if (is_callable ($ class )) {
323- $ identity = $ class ($ identityData );
324- } else {
325- $ identity = new $ class ($ identityData );
326- }
316+ $ identity = is_callable ($ class ) ? $ class ($ identityData ) : new $ class ($ identityData );
327317
328318 if (!($ identity instanceof IdentityInterface)) {
329319 throw new RuntimeException (sprintf (
330320 'Object `%s` does not implement `%s` ' ,
331- get_class ( $ identity) ,
321+ $ identity::class ,
332322 IdentityInterface::class,
333323 ));
334324 }
@@ -373,17 +363,17 @@ public function getUnauthenticatedRedirectUrl(ServerRequestInterface $request):
373363 if ($ uri ->getQuery ()) {
374364 $ redirect .= '? ' . $ uri ->getQuery ();
375365 }
376- $ query = urlencode ($ param ) . '= ' . urlencode ($ redirect );
366+ $ query = urlencode (( string ) $ param ) . '= ' . urlencode ($ redirect );
377367
378368 /** @var array<string, mixed> $url */
379- $ url = parse_url ($ target );
380- if (isset ($ url ['query ' ]) && strlen ($ url ['query ' ])) {
369+ $ url = parse_url (( string ) $ target );
370+ if (isset ($ url ['query ' ]) && strlen (( string ) $ url ['query ' ])) {
381371 $ url ['query ' ] .= '& ' . $ query ;
382372 } else {
383373 $ url ['query ' ] = $ query ;
384374 }
385375 $ fragment = isset ($ url ['fragment ' ]) ? '# ' . $ url ['fragment ' ] : '' ;
386- $ url ['path ' ] = $ url [ ' path ' ] ?? '/ ' ;
376+ $ url ['path ' ] ??= '/ ' ;
387377
388378 return $ url ['path ' ] . '? ' . $ url ['query ' ] . $ fragment ;
389379 }
@@ -404,12 +394,12 @@ public function getLoginRedirect(ServerRequestInterface $request): ?string
404394 if (
405395 empty ($ redirectParam ) ||
406396 !isset ($ params [$ redirectParam ]) ||
407- strlen ( $ params [$ redirectParam ]) === 0
397+ ( string ) $ params [$ redirectParam ] === ''
408398 ) {
409399 return null ;
410400 }
411401
412- $ parsed = parse_url ($ params [$ redirectParam ]);
402+ $ parsed = parse_url (( string ) $ params [$ redirectParam ]);
413403 if ($ parsed === false ) {
414404 return null ;
415405 }
@@ -418,10 +408,10 @@ public function getLoginRedirect(ServerRequestInterface $request): ?string
418408 }
419409 $ parsed += ['path ' => '/ ' , 'query ' => '' ];
420410 if (strlen ($ parsed ['path ' ]) && $ parsed ['path ' ][0 ] !== '/ ' ) {
421- $ parsed ['path ' ] = " / { $ parsed ['path ' ]}" ;
411+ $ parsed ['path ' ] = ' / ' . $ parsed ['path ' ];
422412 }
423413 if ($ parsed ['query ' ]) {
424- $ parsed ['query ' ] = " ? { $ parsed ['query ' ]}" ;
414+ $ parsed ['query ' ] = ' ? ' . $ parsed ['query ' ];
425415 }
426416
427417 $ redirect = $ parsed ['path ' ] . $ parsed ['query ' ];
@@ -525,13 +515,13 @@ public function isImpersonating(ServerRequestInterface $request): bool
525515 protected function getImpersonationProvider (): ImpersonationInterface
526516 {
527517 $ provider = $ this ->getAuthenticationProvider ();
528- if ($ provider === null ) {
518+ if (! $ provider instanceof AuthenticatorInterface ) {
529519 throw new InvalidArgumentException ('No AuthenticationProvider present. ' );
530520 }
531521 if (!($ provider instanceof ImpersonationInterface)) {
532- $ className = get_class ( $ provider) ;
522+ $ className = $ provider::class ;
533523 throw new InvalidArgumentException (
534- " The { $ className } Provider must implement ImpersonationInterface in order to use impersonation. " ,
524+ sprintf ( ' The %s Provider must implement ImpersonationInterface in order to use impersonation. ' , $ className ) ,
535525 );
536526 }
537527
0 commit comments