From 167abf763c1511b576d5e61aefc641278ba917af Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Tue, 20 Dec 2022 18:43:46 +0800 Subject: [PATCH] Fix psalm issues Signed-off-by: Ion Bazan --- src/Check/CpuPerformance.php | 2 +- src/Check/DirReadable.php | 3 ++- src/Check/DirWritable.php | 3 ++- src/Check/ExtensionLoaded.php | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Check/CpuPerformance.php b/src/Check/CpuPerformance.php index 9cbcd81..657f1b3 100644 --- a/src/Check/CpuPerformance.php +++ b/src/Check/CpuPerformance.php @@ -120,7 +120,7 @@ public static function calcPi($precision) $limit = ceil(log($precision) / log(2)) - 1; bcscale($precision + 6); $a = 1; - $b = bcdiv(1, bcsqrt(2)); + $b = bcdiv(1, bcsqrt(2) ?? '0'); $t = 1 / 4; $p = 1; for ($n = 0; $n < $limit; $n++) { diff --git a/src/Check/DirReadable.php b/src/Check/DirReadable.php index 9da4c26..9d018b2 100644 --- a/src/Check/DirReadable.php +++ b/src/Check/DirReadable.php @@ -12,6 +12,7 @@ use function get_class; use function implode; use function is_array; +use function is_countable; use function is_dir; use function is_object; use function is_readable; @@ -90,7 +91,7 @@ public function check() return new Failure(trim($failureString), ['nonDirs' => $nonDirs, 'unreadable' => $unreadable]); } else { return new Success( - count($this->dir) > 1 ? 'All paths are readable directories.' : 'The path is a readable directory.', + is_countable($this->dir) && count($this->dir) > 1 ? 'All paths are readable directories.' : 'The path is a readable directory.', $this->dir ); } diff --git a/src/Check/DirWritable.php b/src/Check/DirWritable.php index 985c10e..0efcac6 100644 --- a/src/Check/DirWritable.php +++ b/src/Check/DirWritable.php @@ -12,6 +12,7 @@ use function get_class; use function implode; use function is_array; +use function is_countable; use function is_dir; use function is_object; use function is_string; @@ -91,7 +92,7 @@ public function check() return new Failure(trim($failureString), ['nonDirs' => $nonDirs, 'unwritable' => $unwritable]); } else { return new Success( - count($this->dir) > 1 ? 'All paths are writable directories.' : 'The path is a writable directory.', + is_countable($this->dir) && count($this->dir) ? 'All paths are writable directories.' : 'The path is a writable directory.', $this->dir ); } diff --git a/src/Check/ExtensionLoaded.php b/src/Check/ExtensionLoaded.php index 3a16853..48f04a2 100644 --- a/src/Check/ExtensionLoaded.php +++ b/src/Check/ExtensionLoaded.php @@ -12,6 +12,7 @@ use function get_class; use function implode; use function is_array; +use function is_countable; use function is_object; use function is_string; use function phpversion; @@ -72,7 +73,7 @@ public function check() return new Failure('Extension ' . implode('', $missing) . ' is not available.', $missing); } } else { - if (count($this->extensions) > 1) { + if (is_countable($this->extensions) && count($this->extensions) > 1) { $versions = []; foreach ($this->extensions as $ext) { $versions[$ext] = phpversion($ext) ? : 'loaded';