From 90273a12acd2f7bb9726f340150840b209083687 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Tue, 10 Dec 2024 06:58:26 +0100 Subject: [PATCH] 1241: Applied coding standards --- src/Entity/ScreenUser.php | 4 +-- .../ScreenUserRequestSubscriber.php | 29 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Entity/ScreenUser.php b/src/Entity/ScreenUser.php index 1f8f9506..719e140c 100644 --- a/src/Entity/ScreenUser.php +++ b/src/Entity/ScreenUser.php @@ -21,10 +21,10 @@ class ScreenUser extends AbstractTenantScopedEntity implements UserInterface, Te { final public const string ROLE_SCREEN = Roles::ROLE_SCREEN; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 180, unique: true)] + #[ORM\Column(type: Types::STRING, length: 180, unique: true)] private string $username; - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)] + #[ORM\Column(type: Types::JSON)] private array $roles = []; #[ORM\OneToOne(inversedBy: 'screenUser', targetEntity: Screen::class)] diff --git a/src/EventSubscriber/ScreenUserRequestSubscriber.php b/src/EventSubscriber/ScreenUserRequestSubscriber.php index 9d65c62d..335bcc58 100644 --- a/src/EventSubscriber/ScreenUserRequestSubscriber.php +++ b/src/EventSubscriber/ScreenUserRequestSubscriber.php @@ -1,5 +1,7 @@ getId()?->jsonSerialize() ?? null; - if ($key === null) { + if (null === $key) { return; } - $this->screenStatusCache->get($key, fn(CacheItemInterface $item) => $this->createCacheEntry($item, $event, $user)); + $this->screenStatusCache->get($key, fn (CacheItemInterface $item) => $this->createCacheEntry($item, $event, $user)); } } } @@ -57,7 +57,7 @@ private function createCacheEntry(CacheItemInterface $item, RequestEvent $event, $request = $event->getRequest(); $referer = $request->headers->get('referer') ?? ''; $url = parse_url($referer); - $queryString = $url['query'] ?? ""; + $queryString = $url['query'] ?? ''; $queryArray = []; if (!empty($queryString)) { @@ -74,7 +74,7 @@ private function createCacheEntry(CacheItemInterface $item, RequestEvent $event, $userAgent = $request->headers->get('user-agent') ?? ''; $ip = $request->getClientIp(); - $host = preg_replace("/\?.*$/i", "", $referer); + $host = preg_replace("/\?.*$/i", '', $referer); $clientMeta = [ 'host' => $host, @@ -83,14 +83,17 @@ private function createCacheEntry(CacheItemInterface $item, RequestEvent $event, ]; $token = $this->security->getToken(); - $decodedToken = $this->tokenManager->decode($token); - $expire = $decodedToken['exp'] ?? 0; - $expireDateTime = (new \DateTime())->setTimestamp($expire); - $now = new \DateTime(); - $tokenExpired = $expireDateTime < $now; + if (null !== $token) { + $decodedToken = $this->tokenManager->decode($token); + $expire = $decodedToken['exp'] ?? 0; + $expireDateTime = (new \DateTime())->setTimestamp($expire); + $now = new \DateTime(); - $clientMeta['tokenExpired'] = $tokenExpired; + $tokenExpired = $expireDateTime < $now; + + $clientMeta['tokenExpired'] = $tokenExpired; + } $screenUser->setClientMeta($clientMeta);