replace string cast with strval function

Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
Simon L. 2025-12-03 14:56:22 +01:00
parent 0db006605a
commit 90ea6c6fa9
5 changed files with 27 additions and 27 deletions

View file

@ -34,7 +34,7 @@ readonly class AuthManager {
error_log(DataConst::GetSessionDirectory() . " has only less than 10KB free space. The login might not succeed because of that!");
}
file_put_contents(DataConst::GetSessionDateFile(), (string)$dateTime);
file_put_contents(DataConst::GetSessionDateFile(), strval($dateTime));
}
$_SESSION[self::SESSION_KEY] = $isLoggedIn;

View file

@ -38,13 +38,13 @@ readonly class ContainerDefinitionFetcher {
*/
private function GetDefinition(): array
{
$data = json_decode((string)file_get_contents(DataConst::GetContainersDefinitionPath()), true, 512, JSON_THROW_ON_ERROR);
$data = json_decode(strval(file_get_contents(DataConst::GetContainersDefinitionPath())), true, 512, JSON_THROW_ON_ERROR);
$additionalContainerNames = [];
foreach ($this->configurationManager->GetEnabledCommunityContainers() as $communityContainer) {
if ($communityContainer !== '') {
$path = DataConst::GetCommunityContainersDirectory() . '/' . $communityContainer . '/' . $communityContainer . '.json';
$additionalData = json_decode((string)file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
$additionalData = json_decode(strval(file_get_contents($path)), true, 512, JSON_THROW_ON_ERROR);
$data = array_merge_recursive($data, $additionalData);
if (isset($additionalData['aio_services_v1'][0]['display_name']) && $additionalData['aio_services_v1'][0]['display_name'] !== '') {
// Store container_name of community containers in variable for later

View file

@ -13,7 +13,7 @@ class ConfigurationManager
{
if(file_exists(DataConst::GetConfigFile()))
{
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
$configContent = strval(file_get_contents(DataConst::GetConfigFile()));
return json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
}
@ -80,7 +80,7 @@ class ConfigurationManager
return '';
}
$content = (string)file_get_contents(DataConst::GetBackupArchivesList());
$content = strval(file_get_contents(DataConst::GetBackupArchivesList()));
$lastBackupLines = explode("\n", $content);
$lastBackupLine = "";
@ -105,7 +105,7 @@ class ConfigurationManager
return [];
}
$content = (string)file_get_contents(DataConst::GetBackupArchivesList());
$content = strval(file_get_contents(DataConst::GetBackupArchivesList()));
$backupLines = explode("\n", $content);
$backupTimes = [];
@ -374,7 +374,7 @@ class ConfigurationManager
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = (string)curl_exec($ch);
$response = strval(curl_exec($ch));
# Get rid of trailing \n
$response = str_replace("\n", "", $response);
@ -657,7 +657,7 @@ class ConfigurationManager
return "";
}
return trim((string)file_get_contents(DataConst::GetBackupPublicKey()));
return trim(strval(file_get_contents(DataConst::GetBackupPublicKey())));
}
public function GetBorgRestorePassword() : string {
@ -814,7 +814,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetDailyBackupTimeFile())) {
return '';
}
$dailyBackupFile = (string)file_get_contents(DataConst::GetDailyBackupTimeFile());
$dailyBackupFile = strval(file_get_contents(DataConst::GetDailyBackupTimeFile()));
$dailyBackupFileArray = explode("\n", $dailyBackupFile);
return $dailyBackupFileArray[0];
}
@ -823,7 +823,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetDailyBackupTimeFile())) {
return false;
}
$dailyBackupFile = (string)file_get_contents(DataConst::GetDailyBackupTimeFile());
$dailyBackupFile = strval(file_get_contents(DataConst::GetDailyBackupTimeFile()));
$dailyBackupFileArray = explode("\n", $dailyBackupFile);
if (isset($dailyBackupFileArray[1]) && $dailyBackupFileArray[1] === 'automaticUpdatesAreNotEnabled') {
return false;
@ -874,7 +874,7 @@ class ConfigurationManager
if (!file_exists(DataConst::GetAdditionalBackupDirectoriesFile())) {
return '';
}
return (string)file_get_contents(DataConst::GetAdditionalBackupDirectoriesFile());
return strval(file_get_contents(DataConst::GetAdditionalBackupDirectoriesFile()));
}
public function GetAdditionalBackupDirectoriesArray() : array {

View file

@ -8,7 +8,7 @@ class DataConst {
return '/mnt/docker-aio-config/data/';
}
return (string)realpath(__DIR__ . '/../../data/');
return strval(realpath(__DIR__ . '/../../data/'));
}
public static function GetSessionDirectory() : string {
@ -16,7 +16,7 @@ class DataConst {
return '/mnt/docker-aio-config/session/';
}
return (string)realpath(__DIR__ . '/../../session/');
return strval(realpath(__DIR__ . '/../../session/'));
}
public static function GetConfigFile() : string {
@ -56,14 +56,14 @@ class DataConst {
}
public static function GetCommunityContainersDirectory() : string {
return (string)realpath(__DIR__ . '/../../../community-containers/');
return strval(realpath(__DIR__ . '/../../../community-containers/'));
}
public static function GetCollaboraSeccompProfilePath() : string {
return (string)realpath(__DIR__ . '/../../cool-seccomp-profile.json');
return strval(realpath(__DIR__ . '/../../cool-seccomp-profile.json'));
}
public static function GetContainersDefinitionPath() : string {
return (string)realpath(__DIR__ . '/../../containers.json');
return strval(realpath(__DIR__ . '/../../containers.json'));
}
}

View file

@ -54,7 +54,7 @@ readonly class DockerActionManager {
throw $e;
}
$responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$responseBody = json_decode(strval($response->getBody()), true, 512, JSON_THROW_ON_ERROR);
if ($responseBody['State']['Running'] === true) {
return ContainerState::Running;
@ -74,7 +74,7 @@ readonly class DockerActionManager {
throw $e;
}
$responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$responseBody = json_decode(strval($response->getBody()), true, 512, JSON_THROW_ON_ERROR);
if ($responseBody['State']['Restarting'] === true) {
return ContainerState::Restarting;
@ -150,16 +150,16 @@ readonly class DockerActionManager {
'containers/%s/logs?stdout=true&stderr=true&timestamps=true',
urlencode($id)
));
$responseBody = (string)$this->guzzleClient->get($url)->getBody();
$responseBody = strval($this->guzzleClient->get($url)->getBody());
$response = "";
$separator = "\r\n";
$line = strtok($responseBody, $separator);
$response = substr((string)$line, 8) . $separator;
$response = substr(strval($line), 8) . $separator;
while ($line !== false) {
$line = strtok($separator);
$response .= substr((string)$line, 8) . $separator;
$response .= substr(strval($line), 8) . $separator;
}
return $response;
@ -417,7 +417,7 @@ readonly class DockerActionManager {
} elseif ($container->GetIdentifier() === 'nextcloud-aio-collabora') {
if (!$this->configurationManager->isSeccompDisabled()) {
// Load reference seccomp profile for collabora
$seccompProfile = (string)file_get_contents(DataConst::GetCollaboraSeccompProfilePath());
$seccompProfile = strval(file_get_contents(DataConst::GetCollaboraSeccompProfilePath()));
$requestBody['HostConfig']['SecurityOpt'] = ["label:disable", "seccomp=$seccompProfile"];
}
@ -537,7 +537,7 @@ readonly class DockerActionManager {
$placeholderPatterns = array_map(static fn(string $p) => '/' . preg_quote($p) . '/', $placeholders); // ["/%PLACEHOLDER1%/", ...]
$placeholderValues = array_map($this->getPlaceholderValue(...), $placeholderNames); // ["val1", "val2"]
// Guaranteed to be non-null because we found the placeholders in the preg_match_all.
return (string) preg_replace($placeholderPatterns, $placeholderValues, $envValue);
return strval(preg_replace($placeholderPatterns, $placeholderValues, $envValue));
}
private function getPlaceholderValue(string $placeholder) : string {
@ -575,7 +575,7 @@ readonly class DockerActionManager {
'NEXTCLOUD_TRUSTED_CACERTS_DIR' => $this->configurationManager->GetTrustedCacertsDir(),
'ADDITIONAL_DIRECTORIES_BACKUP' => $this->configurationManager->GetAdditionalBackupDirectoriesString() !== '' ? 'yes' : '',
'BORGBACKUP_HOST_LOCATION' => $this->configurationManager->GetBorgBackupHostLocation(),
'APACHE_MAX_SIZE' => (string)($this->configurationManager->GetApacheMaxSize()),
'APACHE_MAX_SIZE' => strval($this->configurationManager->GetApacheMaxSize()),
'COLLABORA_SECCOMP_POLICY' => $this->configurationManager->GetCollaboraSeccompPolicy(),
'NEXTCLOUD_STARTUP_APPS' => $this->configurationManager->GetNextcloudStartupApps(),
'NEXTCLOUD_ADDITIONAL_APKS' => $this->configurationManager->GetNextcloudAdditionalApks(),
@ -941,7 +941,7 @@ readonly class DockerActionManager {
throw $e;
}
$responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$responseBody = json_decode(strval($response->getBody()), true, 512, JSON_THROW_ON_ERROR);
$exitCode = $responseBody['State']['ExitCode'];
if (is_int($exitCode)) {
@ -963,7 +963,7 @@ readonly class DockerActionManager {
throw $e;
}
$responseBody = json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
$responseBody = json_decode(strval($response->getBody()), true, 512, JSON_THROW_ON_ERROR);
$exitCode = $responseBody['State']['ExitCode'];
if (is_int($exitCode)) {
@ -1002,7 +1002,7 @@ readonly class DockerActionManager {
return null;
}
return str_replace('T', ' ', (string)$imageOutput['Created']);
return str_replace('T', ' ', strval($imageOutput['Created']));
} catch (\Exception $e) {
return null;
}