From d0147e4875b19d347618571acbba4fd043379445 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Tue, 19 Dec 2023 13:06:08 -0600 Subject: [PATCH] ci: Resolve linter warnings --- src/Auth0Bundle.php | 31 +++++++++---------- src/Controllers/AuthenticationController.php | 11 ++++--- .../BackchannelLogoutController.php | 2 ++ src/Models/User.php | 9 ++++-- src/Security/Authenticator.php | 8 +++-- src/Security/Authorizer.php | 12 ++++--- src/Security/UserProvider.php | 4 ++- src/Stores/SessionStore.php | 8 +++-- 8 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/Auth0Bundle.php b/src/Auth0Bundle.php index 4cd8d96..59127b7 100644 --- a/src/Auth0Bundle.php +++ b/src/Auth0Bundle.php @@ -11,16 +11,14 @@ use Auth0\Symfony\Controllers\AuthenticationController; use Auth0\Symfony\Security\{Authenticator, Authorizer, UserProvider}; use Auth0\Symfony\Stores\SessionStore; -use LogicException; use OpenSSLAsymmetricKey; use Psr\Cache\CacheItemPoolInterface; use Psr\EventDispatcher\ListenerProviderInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\{RequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface}; use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; -use Symfony\Component\DependencyInjection\{ContainerBuilder, Reference}; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\{ContainerBuilder, Reference}; use Symfony\Component\HttpKernel\Bundle\AbstractBundle; final class Auth0Bundle extends AbstractBundle implements BundleInterface @@ -31,45 +29,44 @@ public function configure(DefinitionConfigurator $definition): void } /** - * @param array $config The configuration array. + * @param array $config The configuration array. * @param ContainerConfigurator $container The container configurator. - * @param ContainerBuilder $builder The container builder. + * @param ContainerBuilder $builder The container builder. */ public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void { $sdkConfig = $config['sdk'] ?? []; /** - * @var array{strategy: string, domain: ?string, custom_domain: ?string, client_id: ?string, redirect_uri: ?string, client_secret: ?string, audiences: null|array, organizations: array|null, use_pkce: bool, scopes: array|null, response_mode: string, response_type: string, token_algorithm: ?string, token_jwks_uri: ?string, token_max_age: ?int, token_leeway: ?int, token_cache: ?CacheItemPoolInterface, token_cache_ttl: int, http_client: null|string|ClientInterface, http_max_retries: int, http_request_factory: null|string|RequestFactoryInterface, http_response_factory: null|string|ResponseFactoryInterface, http_stream_factory: null|string|StreamFactoryInterface, http_telemetry: bool, session_storage: ?StoreInterface, session_storage_prefix: ?string, cookie_secret: ?string, cookie_domain: ?string, cookie_expires: int, cookie_path: string, cookie_secure: bool, cookie_same_site: ?string, persist_user: bool, persist_id_token: bool, persist_access_token: bool, persist_refresh_token: bool, transient_storage: ?StoreInterface, transient_storage_prefix: ?string, query_user_info: bool, management_token: ?string, management_token_cache: ?CacheItemPoolInterface, event_listener_provider: null|string|ListenerProviderInterface, client_assertion_signing_key: null|OpenSSLAsymmetricKey|string, client_assertion_signing_algorithm: string, pushed_authorization_request: bool, backchannel_logout_cache: ?CacheItemPoolInterface, backchannel_logout_expires: int} $sdkConfig + * @var array{strategy: string, domain: ?string, custom_domain: ?string, client_id: ?string, redirect_uri: ?string, client_secret: ?string, audiences: null|array, organizations: null|array, use_pkce: bool, scopes: null|array, response_mode: string, response_type: string, token_algorithm: ?string, token_jwks_uri: ?string, token_max_age: ?int, token_leeway: ?int, token_cache: ?CacheItemPoolInterface, token_cache_ttl: int, http_client: null|ClientInterface|string, http_max_retries: int, http_request_factory: null|RequestFactoryInterface|string, http_response_factory: null|ResponseFactoryInterface|string, http_stream_factory: null|StreamFactoryInterface|string, http_telemetry: bool, session_storage: ?StoreInterface, session_storage_prefix: ?string, cookie_secret: ?string, cookie_domain: ?string, cookie_expires: int, cookie_path: string, cookie_secure: bool, cookie_same_site: ?string, persist_user: bool, persist_id_token: bool, persist_access_token: bool, persist_refresh_token: bool, transient_storage: ?StoreInterface, transient_storage_prefix: ?string, query_user_info: bool, management_token: ?string, management_token_cache: ?CacheItemPoolInterface, event_listener_provider: null|ListenerProviderInterface|string, client_assertion_signing_key: null|OpenSSLAsymmetricKey|string, client_assertion_signing_algorithm: string, pushed_authorization_request: bool, backchannel_logout_cache: ?CacheItemPoolInterface, backchannel_logout_expires: int} $sdkConfig */ - $tokenCache = $sdkConfig['token_cache'] ?? 'cache.app'; - if (! $tokenCache instanceOf CacheItemPoolInterface) { + if (! $tokenCache instanceof CacheItemPoolInterface) { $tokenCache = new Reference($tokenCache); } $managementTokenCache = $sdkConfig['management_token_cache'] ?? 'cache.app'; - if (! $managementTokenCache instanceOf CacheItemPoolInterface) { + if (! $managementTokenCache instanceof CacheItemPoolInterface) { $managementTokenCache = new Reference($managementTokenCache); } $backchannelLogoutCache = $sdkConfig['backchannel_logout_cache'] ?? 'cache.app'; - if (! $backchannelLogoutCache instanceOf CacheItemPoolInterface) { + if (! $backchannelLogoutCache instanceof CacheItemPoolInterface) { $backchannelLogoutCache = new Reference($backchannelLogoutCache); } $transientStorage = $sdkConfig['transient_storage'] ?? 'auth0.store_transient'; - if (! $transientStorage instanceOf StoreInterface) { + if (! $transientStorage instanceof StoreInterface) { $transientStorage = new Reference($transientStorage); } $sessionStorage = $sdkConfig['session_storage'] ?? 'auth0.store_session'; - if (! $sessionStorage instanceOf StoreInterface) { + if (! $sessionStorage instanceof StoreInterface) { $sessionStorage = new Reference($sessionStorage); } @@ -78,31 +75,31 @@ public function loadExtension(array $config, ContainerConfigurator $container, C $eventListenerProvider = $sdkConfig['event_listener_provider'] ?? null; - if (! $eventListenerProvider instanceOf ListenerProviderInterface && $eventListenerProvider !== '' && $eventListenerProvider !== null) { + if (! $eventListenerProvider instanceof ListenerProviderInterface && '' !== $eventListenerProvider && null !== $eventListenerProvider) { $eventListenerProvider = new Reference($eventListenerProvider); } $httpClient = $sdkConfig['http_client'] ?? null; - if (! $httpClient instanceOf ClientInterface && $httpClient !== '' && $httpClient !== null) { + if (! $httpClient instanceof ClientInterface && '' !== $httpClient && null !== $httpClient) { $httpClient = new Reference($httpClient); } $httpRequestFactory = $sdkConfig['http_request_factory'] ?? null; - if (! $httpRequestFactory instanceOf RequestFactoryInterface && $httpRequestFactory !== '' && $httpRequestFactory !== null) { + if (! $httpRequestFactory instanceof RequestFactoryInterface && '' !== $httpRequestFactory && null !== $httpRequestFactory) { $httpRequestFactory = new Reference($httpRequestFactory); } $httpResponseFactory = $sdkConfig['http_response_factory'] ?? null; - if (! $httpResponseFactory instanceOf ResponseFactoryInterface && $httpResponseFactory !== '' && $httpResponseFactory !== null) { + if (! $httpResponseFactory instanceof ResponseFactoryInterface && '' !== $httpResponseFactory && null !== $httpResponseFactory) { $httpResponseFactory = new Reference($httpResponseFactory); } $httpStreamFactory = $sdkConfig['http_stream_factory'] ?? null; - if (! $httpStreamFactory instanceOf StreamFactoryInterface && $httpStreamFactory !== '' && $httpStreamFactory !== null) { + if (! $httpStreamFactory instanceof StreamFactoryInterface && '' !== $httpStreamFactory && null !== $httpStreamFactory) { $httpStreamFactory = new Reference($httpStreamFactory); } diff --git a/src/Controllers/AuthenticationController.php b/src/Controllers/AuthenticationController.php index 5f0ccec..e8b85ce 100644 --- a/src/Controllers/AuthenticationController.php +++ b/src/Controllers/AuthenticationController.php @@ -7,17 +7,16 @@ use Auth0\SDK\Auth0; use Auth0\Symfony\Contracts\Controllers\AuthenticationControllerInterface; use Auth0\Symfony\Security\Authenticator; -use Psr\Cache\InvalidArgumentException; -use LogicException; use Psr\Container\ContainerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Exception\{BadRequestException, ConflictingHeadersException, SuspiciousOperationException}; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; -use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; -use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; -use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\Routing\RouterInterface; use Throwable; +use function is_array; +use function is_string; + final class AuthenticationController extends AbstractController implements AuthenticationControllerInterface { public function __construct( @@ -29,6 +28,8 @@ public function __construct( /** * @psalm-suppress InternalMethod + * + * @param Request $request */ public function callback(Request $request): Response { diff --git a/src/Controllers/BackchannelLogoutController.php b/src/Controllers/BackchannelLogoutController.php index 330ad63..0d54fca 100644 --- a/src/Controllers/BackchannelLogoutController.php +++ b/src/Controllers/BackchannelLogoutController.php @@ -24,6 +24,8 @@ public function __construct( /** * @psalm-suppress InternalMethod + * + * @param Request $request */ public function handle(Request $request): Response { diff --git a/src/Models/User.php b/src/Models/User.php index f3b4a0c..920d631 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -10,6 +10,9 @@ use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface; use function array_key_exists; +use function is_array; +use function is_bool; +use function is_int; use function is_string; class User implements SymfonyUserInterface, UserInterface @@ -37,7 +40,7 @@ public function eraseCredentials(): void /** * @param string $name - * @param mixed $default + * @param mixed $default * * @return mixed */ @@ -163,7 +166,7 @@ public function getLastLoginAt(): ?DateTimeInterface public function getLastPasswordResetAt(): ?DateTimeInterface { - $lastPasswordResetAt =$this->data['last_password_reset']; + $lastPasswordResetAt = $this->data['last_password_reset']; if (! is_string($lastPasswordResetAt)) { return null; @@ -305,7 +308,7 @@ public function getUserIdentifier(): string /** * @param string $name - * @param mixed $default + * @param mixed $default * * @return mixed */ diff --git a/src/Security/Authenticator.php b/src/Security/Authenticator.php index 620e190..8768660 100644 --- a/src/Security/Authenticator.php +++ b/src/Security/Authenticator.php @@ -16,14 +16,16 @@ use Symfony\Component\Security\Http\Authenticator\Passport\{Passport, SelfValidatingPassport}; use Throwable; +use function is_array; +use function is_string; + final class Authenticator extends AbstractAuthenticator implements AuthenticatorInterface { /** - * @param array $configuration - * @param Service $service + * @param array $configuration + * @param Service $service * @param RouterInterface $router * @param LoggerInterface $logger - * @return void */ public function __construct( public array $configuration, diff --git a/src/Security/Authorizer.php b/src/Security/Authorizer.php index 0e70549..e276cd5 100644 --- a/src/Security/Authorizer.php +++ b/src/Security/Authorizer.php @@ -14,14 +14,14 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\{Passport, SelfValidatingPassport}; +use function is_string; + final class Authorizer extends AbstractAuthenticator implements AuthorizerInterface { /** - * @param array $configuration - * @param Service $service + * @param array $configuration + * @param Service $service * @param LoggerInterface $logger - * - * @return void */ public function __construct( private array $configuration, @@ -32,6 +32,8 @@ public function __construct( /** * @psalm-suppress InternalMethod + * + * @param Request $request */ public function authenticate(Request $request): Passport { @@ -100,6 +102,8 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, /** * @psalm-suppress InternalMethod + * + * @param Request $request */ public function supports(Request $request): ?bool { diff --git a/src/Security/UserProvider.php b/src/Security/UserProvider.php index 5ba1dbb..d4bf4c5 100644 --- a/src/Security/UserProvider.php +++ b/src/Security/UserProvider.php @@ -15,6 +15,8 @@ use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\{UserInterface as SymfonyUserInterface, UserProviderInterface as SymfonyUserProviderInterface}; +use function is_array; + /** * @template-implements SymfonyUserProviderInterface */ @@ -59,7 +61,7 @@ public function refreshUser(SymfonyUserInterface $user): SymfonyUserInterface } /** - * @param UserInterface|string $class + * @param string|UserInterface $class */ public function supportsClass($class): bool { diff --git a/src/Stores/SessionStore.php b/src/Stores/SessionStore.php index 4f29fb1..506cbb4 100644 --- a/src/Stores/SessionStore.php +++ b/src/Stores/SessionStore.php @@ -11,11 +11,15 @@ use Symfony\Component\HttpFoundation\{Request, RequestStack}; use Throwable; +use function gettype; +use function is_array; +use function is_string; + final class SessionStore implements StoreInterface { /** - * @param string $namespace - * @param RequestStack $requestStack + * @param string $namespace + * @param RequestStack $requestStack * @param LoggerInterface $logger * * @psalm-suppress DocblockTypeContradiction