Skip to content

Commit

Permalink
apply SonarCloud suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
reithor committed Dec 11, 2024
1 parent fa6a52f commit 1dfa078
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/bundle/Core/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 === '\\') {
Expand Down

0 comments on commit 1dfa078

Please sign in to comment.