From f0ade4ad28d4606f8e680c04927fbee9e8dbb9b3 Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Sat, 17 Jan 2026 21:24:56 +0100 Subject: [PATCH] refactor(astrolabe): add PHP property types to fix Psalm errors Add explicit property type declarations to IdpTokenRefresher, CredentialsController, OAuthController, and McpServerClient classes. This improves type safety and allows Psalm to properly infer types, eliminating MissingPropertyType and many MixedMethodCall errors. Also adds IClient import where needed and validates getSystemValue returns to ensure string types before use. Co-Authored-By: Claude Opus 4.5 --- .../lib/Controller/CredentialsController.php | 14 +- .../lib/Controller/OAuthController.php | 19 +- .../lib/Service/IdpTokenRefresher.php | 12 +- .../astrolabe/lib/Service/McpServerClient.php | 12 +- third_party/astrolabe/psalm-baseline.xml | 340 ++---------------- 5 files changed, 71 insertions(+), 326 deletions(-) diff --git a/third_party/astrolabe/lib/Controller/CredentialsController.php b/third_party/astrolabe/lib/Controller/CredentialsController.php index 2ba87ff..4d414a2 100644 --- a/third_party/astrolabe/lib/Controller/CredentialsController.php +++ b/third_party/astrolabe/lib/Controller/CredentialsController.php @@ -23,13 +23,13 @@ use Psr\Log\LoggerInterface; * Handles storing and validating app passwords for multi-user BasicAuth mode. */ class CredentialsController extends Controller { - private $tokenStorage; - private $userSession; - private $logger; - private $config; - private $client; - private $httpClientService; - private $urlGenerator; + private McpTokenStorage $tokenStorage; + private IUserSession $userSession; + private LoggerInterface $logger; + private IConfig $config; + private McpServerClient $client; + private IClientService $httpClientService; + private IURLGenerator $urlGenerator; public function __construct( string $appName, diff --git a/third_party/astrolabe/lib/Controller/OAuthController.php b/third_party/astrolabe/lib/Controller/OAuthController.php index b6698b2..aa21811 100644 --- a/third_party/astrolabe/lib/Controller/OAuthController.php +++ b/third_party/astrolabe/lib/Controller/OAuthController.php @@ -12,6 +12,7 @@ use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IL10N; @@ -32,15 +33,15 @@ use Psr\Log\LoggerInterface; * - Confidential clients: PKCE + client_secret (defense in depth) */ class OAuthController extends Controller { - private $config; - private $session; - private $userSession; - private $urlGenerator; - private $tokenStorage; - private $logger; - private $l; - private $httpClient; - private $client; + private IConfig $config; + private ISession $session; + private IUserSession $userSession; + private IURLGenerator $urlGenerator; + private McpTokenStorage $tokenStorage; + private LoggerInterface $logger; + private IL10N $l; + private IClient $httpClient; + private McpServerClient $client; public function __construct( string $appName, diff --git a/third_party/astrolabe/lib/Service/IdpTokenRefresher.php b/third_party/astrolabe/lib/Service/IdpTokenRefresher.php index f35179d..682e105 100644 --- a/third_party/astrolabe/lib/Service/IdpTokenRefresher.php +++ b/third_party/astrolabe/lib/Service/IdpTokenRefresher.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\Astrolabe\Service; +use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; use Psr\Log\LoggerInterface; @@ -18,10 +19,10 @@ use Psr\Log\LoggerInterface; * Public clients without client_secret cannot refresh tokens. */ class IdpTokenRefresher { - private $config; - private $httpClient; - private $logger; - private $mcpServerClient; + private IConfig $config; + private IClient $httpClient; + private LoggerInterface $logger; + private McpServerClient $mcpServerClient; public function __construct( IConfig $config, @@ -56,6 +57,9 @@ class IdpTokenRefresher { private function getNextcloudBaseUrl(): string { // Check for explicit internal URL config (for custom container setups) $internalUrl = $this->config->getSystemValue('astrolabe_internal_url', ''); + if (!is_string($internalUrl)) { + $internalUrl = ''; + } if (!empty($internalUrl)) { // Validate URL format if (!filter_var($internalUrl, FILTER_VALIDATE_URL)) { diff --git a/third_party/astrolabe/lib/Service/McpServerClient.php b/third_party/astrolabe/lib/Service/McpServerClient.php index 2338135..4316ed9 100644 --- a/third_party/astrolabe/lib/Service/McpServerClient.php +++ b/third_party/astrolabe/lib/Service/McpServerClient.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\Astrolabe\Service; +use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\IConfig; use Psr\Log\LoggerInterface; @@ -16,10 +17,10 @@ use Psr\Log\LoggerInterface; * for all management operations. */ class McpServerClient { - private $httpClient; - private $config; - private $logger; - private $baseUrl; + private IClient $httpClient; + private IConfig $config; + private LoggerInterface $logger; + private string $baseUrl; public function __construct( IClientService $clientService, @@ -31,7 +32,8 @@ class McpServerClient { $this->logger = $logger; // Get MCP server configuration from Nextcloud config - $this->baseUrl = $this->config->getSystemValue('mcp_server_url', 'http://localhost:8000'); + $baseUrl = $this->config->getSystemValue('mcp_server_url', 'http://localhost:8000'); + $this->baseUrl = is_string($baseUrl) ? $baseUrl : 'http://localhost:8000'; } /** diff --git a/third_party/astrolabe/psalm-baseline.xml b/third_party/astrolabe/psalm-baseline.xml index 8cd76ea..cf66cc8 100644 --- a/third_party/astrolabe/psalm-baseline.xml +++ b/third_party/astrolabe/psalm-baseline.xml @@ -84,19 +84,8 @@ - - - - - - - - - - getBody()]]> - @@ -105,67 +94,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + getBody()]]> + @@ -174,36 +107,19 @@ - - - - - - - - - - - - + + - getBody()]]> - getBody()]]> - - getBody()]]> - getBody()]]> - urlGenerator->linkToRoute('settings.PersonalSettings.index', [ - 'section' => 'astrolabe', - 'error' => urlencode($e->getMessage()) - ])]]> - urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'astrolabe'])]]> - urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'astrolabe'])]]> - urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'astrolabe'])]]> + + + + + @@ -226,116 +142,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - getUID()]]> - getUID()]]> + + getBody()]]> + getBody()]]> + + + getBody()]]> + getBody()]]> + @@ -400,18 +235,10 @@ - - - - - - - getBody()]]> - - getBody()]]> - getBody()]]> + + @@ -421,70 +248,37 @@ - - - - - - - - - - - - - - - - - - - - - - + + getBody()]]> + getBody()]]> + getBody()]]> + - - - - - - - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> - getBody()]]> + @@ -497,17 +291,6 @@ - - - - - - - - - - - @@ -582,61 +365,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - baseUrl]]> - @@ -649,12 +378,23 @@ - baseUrl]]> config->getSystemValue('mcp_server_public_url', $this->baseUrl)]]> + + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + getBody()]]> + - @@ -686,8 +426,6 @@ - -