Skip to content

Commit

Permalink
1241: Applied coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Dec 10, 2024
1 parent 6a4f19b commit 90273a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Entity/ScreenUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
29 changes: 16 additions & 13 deletions src/EventSubscriber/ScreenUserRequestSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\EventSubscriber;

use App\Entity\ScreenUser;
Expand All @@ -22,9 +24,7 @@ public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly bool $trackScreenInfo = false,
private readonly int $trackScreenInfoUpdateIntervalSeconds = 5 * 60,
)
{
}
) {}

/**
* @throws InvalidArgumentException
Expand All @@ -39,11 +39,11 @@ public function onKernelRequest(RequestEvent $event): void
if ($user instanceof ScreenUser) {
$key = $user->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));
}
}
}
Expand All @@ -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)) {
Expand All @@ -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,
Expand All @@ -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);

Expand Down

0 comments on commit 90273a1

Please sign in to comment.