From 1dfa0780e5f5e71f13a40fa70dc401bac4449996 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Wed, 11 Dec 2024 14:44:45 +0100 Subject: [PATCH] apply SonarCloud suggestions --- src/bundle/Core/Command/ReindexCommand.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bundle/Core/Command/ReindexCommand.php b/src/bundle/Core/Command/ReindexCommand.php index 936425d21f..8af26d403b 100644 --- a/src/bundle/Core/Command/ReindexCommand.php +++ b/src/bundle/Core/Command/ReindexCommand.php @@ -28,6 +28,9 @@ class ReindexCommand extends Command implements BackwardCompatibleCommand { + private const IBEXA_CLOUD_CONFIG_FILE = '/run/config.json'; + private const LINUX_CPUINFO_FILE = '/proc/cpuinfo'; + /** @var \Ibexa\Core\Search\Common\Indexer|\Ibexa\Core\Search\Common\IncrementalIndexer */ private $searchIndexer; @@ -450,17 +453,17 @@ private function getPhpPath() private function getNumberOfCPUCores() { $cores = 1; - if (isset($_SERVER['PLATFORM_BRANCH']) && is_readable('/run/config.json') && is_file('/run/config.json')) { + if (isset($_SERVER['PLATFORM_BRANCH']) && is_readable(self::IBEXA_CLOUD_CONFIG_FILE) && is_file(self::IBEXA_CLOUD_CONFIG_FILE)) { // Ibexa Cloud: read #cpus from config - $configJsonEncoded = file_get_contents('/run/config.json'); + $configJsonEncoded = file_get_contents(self::IBEXA_CLOUD_CONFIG_FILE); if ($configJsonEncoded === false) { return 1; } $configJson = json_decode($configJsonEncoded); $cores = isset($configJson->info->limits->cpu) ? max(1, (int) ($configJson->info->limits->cpu)) : 1; - } elseif (is_readable('/proc/cpuinfo') && is_file('/proc/cpuinfo')) { + } elseif (is_readable(self::LINUX_CPUINFO_FILE) && is_file(self::LINUX_CPUINFO_FILE)) { // Linux (and potentially Windows with linux sub systems) - $cpuinfo = file_get_contents('/proc/cpuinfo'); + $cpuinfo = file_get_contents(self::LINUX_CPUINFO_FILE); preg_match_all('/^processor/m', $cpuinfo, $matches); $cores = count($matches[0]); } elseif (DIRECTORY_SEPARATOR === '\\') {