From c3bb9810466cfbb7a2ccfa328d72cb4929abf571 Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Wed, 4 Feb 2026 23:11:49 +0100 Subject: [PATCH] handle problems Signed-off-by: Simon L. --- php/psalm-baseline.xml | 38 ++++++++++++++++++- php/psalm.xml | 2 +- php/src/ContainerDefinitionFetcher.php | 16 ++++---- .../Controller/ConfigurationController.php | 1 - php/src/Data/ConfigurationManager.php | 6 +-- php/src/Docker/DockerActionManager.php | 14 +++---- 6 files changed, 56 insertions(+), 21 deletions(-) diff --git a/php/psalm-baseline.xml b/php/psalm-baseline.xml index a9b7140d..b8007425 100644 --- a/php/psalm-baseline.xml +++ b/php/psalm-baseline.xml @@ -1,2 +1,38 @@ - + + + + get(Guard::class)]]> + get(\AIO\Auth\AuthManager::class)]]> + get(\AIO\Data\ConfigurationManager::class)]]> + + + + + + + + + + + + getParsedBody()]]> + + + + + get(DockerHubManager::class)]]> + get(GitHubContainerRegistryManager::class)]]> + get(\AIO\Auth\PasswordGenerator::class)]]> + get(\AIO\ContainerDefinitionFetcher::class)]]> + get(\AIO\Data\ConfigurationManager::class)]]> + get(\AIO\Data\ConfigurationManager::class)]]> + get(\AIO\Data\ConfigurationManager::class)]]> + + + + + + + + diff --git a/php/psalm.xml b/php/psalm.xml index dae6f935..67ae22db 100644 --- a/php/psalm.xml +++ b/php/psalm.xml @@ -6,7 +6,7 @@ errorBaseline="psalm-baseline.xml" findUnusedBaselineEntry="true" findUnusedCode="false" - errorLevel="2" + errorLevel="1" > diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index 7be3d0cc..486f1288 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -108,9 +108,9 @@ readonly class ContainerDefinitionFetcher { foreach ($entry['ports'] as $value) { $ports->AddPort( new ContainerPort( - $value['port_number'], - $value['ip_binding'], - $value['protocol'] + (string) $value['port_number'], + (string) $value['ip_binding'], + (string) $value['protocol'] ) ); } @@ -155,9 +155,9 @@ readonly class ContainerDefinitionFetcher { } $volumes->AddVolume( new ContainerVolume( - $value['source'], - $value['destination'], - $value['writeable'] + (string) $value['source'], + (string) $value['destination'], + (bool) $value['writeable'] ) ); } @@ -335,9 +335,9 @@ readonly class ContainerDefinitionFetcher { } $containers[] = new Container( - $entry['container_name'], + (string) $entry['container_name'], $displayName, - $entry['image'], + (string) $entry['image'], $restartPolicy, $maxShutdownTime, $ports, diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index 09be2abe..c81395a0 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -114,7 +114,6 @@ readonly class ConfigurationController { $cc = $this->configurationManager->listAvailableCommunityContainers(); $enabledCC = []; /** - * @psalm-suppress PossiblyNullIterator * @psalm-var string $item */ foreach ($request->getParsedBody() as $item) { diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 8eb4e3ce..18698f4b 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -341,10 +341,10 @@ class ConfigurationManager } if ($secretId === 'BORGBACKUP_PASSWORD' && !file_exists(DataConst::GetBackupSecretFile())) { - $this->doubleSafeBackupSecret($secrets[$secretId]); + $this->doubleSafeBackupSecret((string)$secrets[$secretId]); } - return $secrets[$secretId]; + return (string)$secrets[$secretId]; } public function getRegisteredSecret(string $secretId) : string { @@ -704,7 +704,7 @@ class ConfigurationManager if ($configValue === '') { return $defaultValue; } - return $configValue; + return (string) $configValue; } if (file_exists(DataConst::GetConfigFile())) { diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 1af835d8..35c889f9 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -57,7 +57,7 @@ readonly class DockerActionManager { /** @var array */ $responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); - if ($responseBody['State']['Running'] === true) { + if ($responseBody['State']['Running'] ?? false === true) { return ContainerState::Running; } else { return ContainerState::Stopped; @@ -78,7 +78,7 @@ readonly class DockerActionManager { /** @var array */ $responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); - if ($responseBody['State']['Restarting'] === true) { + if ($responseBody['State']['Restarting'] ?? false === true) { return ContainerState::Restarting; } else { return ContainerState::NotRestarting; @@ -656,11 +656,11 @@ readonly class DockerActionManager { try { /** @var array */ $output = json_decode($this->guzzleClient->get($url)->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); - $imageNameArray = explode(':', $output['Config']['Image']); + $imageNameArray = explode(':', (string) $output['Config']['Image']); if (count($imageNameArray) === 2) { $imageName = $imageNameArray[0]; } else { - error_log("No tag was found when getting the current channel. You probably did not follow the documentation correctly. Changing the imageName to the default " . $output['Config']['Image']); + error_log("No tag was found when getting the current channel. You probably did not follow the documentation correctly. Changing the imageName to the default " . (string) $output['Config']['Image']); $imageName = (string) $output['Config']['Image']; } apcu_add($cacheKey, $imageName); @@ -685,7 +685,7 @@ readonly class DockerActionManager { try { /** @var array */ $output = json_decode($this->guzzleClient->get($url)->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); - $tagArray = explode(':', $output['Config']['Image']); + $tagArray = explode(':', (string) $output['Config']['Image']); if (count($tagArray) === 2) { $tag = $tagArray[1]; } else { @@ -898,7 +898,7 @@ readonly class DockerActionManager { $responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); /** @var null|int */ - $exitCode = $responseBody['State']['ExitCode']; + $exitCode = $responseBody['State']['ExitCode'] ?? null; if (is_int($exitCode)) { return $exitCode; } else { @@ -922,7 +922,7 @@ readonly class DockerActionManager { $responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR); /** @var null|int */ - $exitCode = $responseBody['State']['ExitCode']; + $exitCode = $responseBody['State']['ExitCode'] ?? null; if (is_int($exitCode)) { return $exitCode; } else {