From 449ef0d994fbce7891529c1fdaa440575f34c548 Mon Sep 17 00:00:00 2001 From: Thomas Bley Date: Mon, 20 Sep 2021 12:18:49 +0200 Subject: [PATCH] fixed Uncaught Error: Call to undefined function shell_exec() --- .../Internal/Analyzer/ProjectAnalyzer.php | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index d19e264e3..b4eee08a6 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1449,9 +1449,20 @@ class ProjectAnalyzer return 1; } - $has_nproc = trim((string) @shell_exec('command -v nproc')); - if ($has_nproc) { - $ret = @shell_exec('nproc'); + if (\function_exists('shell_exec')) { + $has_nproc = trim((string) @shell_exec('command -v nproc')); + if ($has_nproc) { + $ret = @shell_exec('nproc'); + if (is_string($ret)) { + $ret = trim($ret); + $tmp = filter_var($ret, FILTER_VALIDATE_INT); + if (is_int($tmp)) { + return $tmp; + } + } + } + + $ret = @shell_exec('sysctl -n hw.ncpu'); if (is_string($ret)) { $ret = trim($ret); $tmp = filter_var($ret, FILTER_VALIDATE_INT); @@ -1461,15 +1472,6 @@ class ProjectAnalyzer } } - $ret = @shell_exec('sysctl -n hw.ncpu'); - if (is_string($ret)) { - $ret = trim($ret); - $tmp = filter_var($ret, FILTER_VALIDATE_INT); - if (is_int($tmp)) { - return $tmp; - } - } - if (is_readable('/proc/cpuinfo')) { $cpuinfo = file_get_contents('/proc/cpuinfo'); $count = substr_count($cpuinfo, 'processor');