Skip to content

Commit

Permalink
Re-order the default finders (#27)
Browse files Browse the repository at this point in the history
Re-order the default finders to a more sensible order:

- nproc is probably the most reliable way
- if on windows, wmic is probably the best way
- cpuinfo is the least good one, hence placed as last
  • Loading branch information
theofidry authored Dec 4, 2022
1 parent e33ff4f commit f5f3fa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/CpuCoreCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public static function getDefaultFinders(): array
{
/** @var list<class-string<CpuCoreFinder>> $finders */
return [
new CpuInfoFinder(),
new NProcFinder(),
new WindowsWmicFinder(),
new HwFinder(),
new CpuInfoFinder(),
];
}
}
13 changes: 7 additions & 6 deletions src/NProcFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Fidry\CpuCounter\Exec\ExecException;
use Fidry\CpuCounter\Exec\ShellExec;
use function filter_var;
use function function_exists;
use function is_int;
use function trim;
use const FILTER_VALIDATE_INT;
Expand All @@ -24,17 +25,17 @@
* @see https://github.com/infection/infection/blob/fbd8c44/src/Resource/Processor/CpuCoresCountProvider.php#L69-L82
* @see https://unix.stackexchange.com/questions/146051/number-of-processors-in-proc-cpuinfo
*/
final class NProcFinder
final class NProcFinder implements CpuCoreFinder
{
private function __construct()
{
}

/**
* @return positive-int|null
*/
public static function find(): ?int
public function find(): ?int
{
if (!function_exists('shell_exec')) {
return null;
}

if (!self::supportsNproc()) {
return null;
}
Expand Down

0 comments on commit f5f3fa8

Please sign in to comment.