From a29d68f09a8b1b46b141ed3d4330a289afb9a256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:20:52 +0100 Subject: [PATCH] Move checking if proc_open function exists to the executor (#92) --- src/Executor/ProcOpen.php | 7 ++++++- src/Finder/ProcOpenBasedFinder.php | 4 ---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Executor/ProcOpen.php b/src/Executor/ProcOpen.php index f5d0f4c..acecb9e 100644 --- a/src/Executor/ProcOpen.php +++ b/src/Executor/ProcOpen.php @@ -14,6 +14,7 @@ namespace Fidry\CpuCoreCounter\Executor; use function fclose; +use function function_exists; use function is_resource; use function proc_close; use function proc_open; @@ -22,10 +23,14 @@ final class ProcOpen { /** - * @return array{string, string} STDOUT & STDERR tuple + * @return array{string, string}|null STDOUT & STDERR tuple */ public static function execute(string $command): ?array { + if (!function_exists('proc_open')) { + return null; + } + $pipes = []; $process = @proc_open( diff --git a/src/Finder/ProcOpenBasedFinder.php b/src/Finder/ProcOpenBasedFinder.php index f272cee..4ec12a4 100644 --- a/src/Finder/ProcOpenBasedFinder.php +++ b/src/Finder/ProcOpenBasedFinder.php @@ -63,10 +63,6 @@ public function diagnose(): string */ public function find(): ?int { - if (!function_exists('proc_open')) { - return null; - } - $output = ProcOpen::execute($this->getCommand()); if (null === $output) {