From 1bb85f5c617174fa802baf96a9580fafc19c76b0 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Mon, 2 Feb 2026 11:37:59 +0100 Subject: [PATCH 1/2] refactor: readonly class feature Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/Model/Token.php | 49 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/Model/Token.php b/lib/Model/Token.php index f5f66c00..2ddef779 100644 --- a/lib/Model/Token.php +++ b/lib/Model/Token.php @@ -1,6 +1,7 @@ idToken = $tokenData['id_token'] ?? null; - $this->accessToken = $tokenData['access_token']; - $this->expiresIn = $tokenData['expires_in']; - $this->refreshExpiresIn = $tokenData['refresh_expires_in'] ?? null; - $this->refreshToken = $tokenData['refresh_token'] ?? null; - $this->createdAt = $tokenData['created_at'] ?? time(); - $this->providerId = $tokenData['provider_id'] ?? null; + public static function fromArray(array $tokenData): self { + return new self( + idToken: $tokenData['id_token'] ?? null, + accessToken: $tokenData['access_token'], + expiresIn: $tokenData['expires_in'], + refreshExpiresIn: $tokenData['refresh_expires_in'] ?? null, + refreshToken: $tokenData['refresh_token'] ?? null, + createdAt: $tokenData['created_at'] ?? time(), + providerId: $tokenData['provider_id'] ?? null, + ); } public function getAccessToken(): string { @@ -43,8 +49,7 @@ public function getExpiresIn(): int { } public function getExpiresInFromNow(): int { - $expiresAt = $this->createdAt + $this->expiresIn; - return $expiresAt - time(); + return ($this->createdAt + $this->expiresIn) - time(); } public function getRefreshExpiresIn(): ?int { @@ -53,12 +58,10 @@ public function getRefreshExpiresIn(): ?int { public function getRefreshExpiresInFromNow(): int { // if there is no refresh_expires_in, we assume the refresh token never expires - // so we don't need getRefreshExpiresInFromNow if ($this->refreshExpiresIn === null) { return 0; } - $refreshExpiresAt = $this->createdAt + $this->refreshExpiresIn; - return $refreshExpiresAt - time(); + return ($this->createdAt + $this->refreshExpiresIn) - time(); } public function getRefreshToken(): ?string { @@ -93,7 +96,7 @@ public function refreshIsExpiring(): bool { return time() > ($this->createdAt + (int)($this->refreshExpiresIn / 2)); } - public function getCreatedAt() { + public function getCreatedAt(): int { return $this->createdAt; } From 0589a56f861b368b3ce534e05de1f192cc1f5653 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Mon, 2 Feb 2026 11:41:28 +0100 Subject: [PATCH 2/2] fix: ci Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/Model/Token.php | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/Model/Token.php b/lib/Model/Token.php index 2ddef779..ebd629b2 100644 --- a/lib/Model/Token.php +++ b/lib/Model/Token.php @@ -11,29 +11,24 @@ use JsonSerializable; -readonly class Token implements JsonSerializable { - - public function __construct( - private ?string $idToken, - private string $accessToken, - private int $expiresIn, - private ?int $refreshExpiresIn, - private ?string $refreshToken, - private int $createdAt, - private ?int $providerId, - ) { - } - - public static function fromArray(array $tokenData): self { - return new self( - idToken: $tokenData['id_token'] ?? null, - accessToken: $tokenData['access_token'], - expiresIn: $tokenData['expires_in'], - refreshExpiresIn: $tokenData['refresh_expires_in'] ?? null, - refreshToken: $tokenData['refresh_token'] ?? null, - createdAt: $tokenData['created_at'] ?? time(), - providerId: $tokenData['provider_id'] ?? null, - ); +class Token implements JsonSerializable { + + private readonly ?string $idToken; + private readonly string $accessToken; + private readonly int $expiresIn; + private readonly ?int $refreshExpiresIn; + private readonly ?string $refreshToken; + private readonly int $createdAt; + private readonly ?int $providerId; + + public function __construct(array $tokenData) { + $this->idToken = $tokenData['id_token'] ?? null; + $this->accessToken = $tokenData['access_token']; + $this->expiresIn = $tokenData['expires_in']; + $this->refreshExpiresIn = $tokenData['refresh_expires_in'] ?? null; + $this->refreshToken = $tokenData['refresh_token'] ?? null; + $this->createdAt = $tokenData['created_at'] ?? time(); + $this->providerId = $tokenData['provider_id'] ?? null; } public function getAccessToken(): string {