Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions lib/Model/Token.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -12,30 +13,30 @@

class Token implements JsonSerializable {

private ?string $idToken;
private string $accessToken;
private int $expiresIn;
private ?int $refreshExpiresIn;
private ?string $refreshToken;
private int $createdAt;
private ?int $providerId;
private readonly ?string $idToken;

Check failure on line 16 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

ParseError

lib/Model/Token.php:16:19: ParseError: Syntax error, unexpected '?', expecting T_VARIABLE on line 16 (see https://psalm.dev/173)
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;

Check failure on line 25 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:25:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$idToken is not defined (see https://psalm.dev/040)
$this->accessToken = $tokenData['access_token'];

Check failure on line 26 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:26:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$accessToken is not defined (see https://psalm.dev/040)
$this->expiresIn = $tokenData['expires_in'];

Check failure on line 27 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:27:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$expiresIn is not defined (see https://psalm.dev/040)
$this->refreshExpiresIn = $tokenData['refresh_expires_in'] ?? null;

Check failure on line 28 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:28:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$refreshExpiresIn is not defined (see https://psalm.dev/040)
$this->refreshToken = $tokenData['refresh_token'] ?? null;

Check failure on line 29 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:29:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$refreshToken is not defined (see https://psalm.dev/040)
$this->createdAt = $tokenData['created_at'] ?? time();

Check failure on line 30 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:30:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$createdAt is not defined (see https://psalm.dev/040)
$this->providerId = $tokenData['provider_id'] ?? null;

Check failure on line 31 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyAssignment

lib/Model/Token.php:31:3: UndefinedThisPropertyAssignment: Instance property OCA\UserOIDC\Model\Token::$providerId is not defined (see https://psalm.dev/040)
}

public function getAccessToken(): string {
return $this->accessToken;

Check failure on line 35 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Model/Token.php:35:10: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Model\Token::$accessToken is not defined (see https://psalm.dev/041)
}

public function getIdToken(): ?string {
return $this->idToken;

Check failure on line 39 in lib/Model/Token.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedThisPropertyFetch

lib/Model/Token.php:39:10: UndefinedThisPropertyFetch: Instance property OCA\UserOIDC\Model\Token::$idToken is not defined (see https://psalm.dev/041)
}

public function getExpiresIn(): int {
Expand All @@ -43,8 +44,7 @@
}

public function getExpiresInFromNow(): int {
$expiresAt = $this->createdAt + $this->expiresIn;
return $expiresAt - time();
return ($this->createdAt + $this->expiresIn) - time();
}

public function getRefreshExpiresIn(): ?int {
Expand All @@ -53,12 +53,10 @@

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 {
Expand Down Expand Up @@ -93,7 +91,7 @@
return time() > ($this->createdAt + (int)($this->refreshExpiresIn / 2));
}

public function getCreatedAt() {
public function getCreatedAt(): int {
return $this->createdAt;
}

Expand Down
Loading