From 85b4d8dbd4c5b2246cb842925d0be11a240650ad Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sun, 27 Oct 2024 12:10:24 +0100 Subject: [PATCH] Fix phpstan errors --- src/Collection/Collection.php | 10 ++++------ src/Host/HostCollection.php | 4 ++-- src/Ssh/SshClient.php | 6 ------ src/Task/TaskCollection.php | 4 ++-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index d2c7e154c..273840632 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -26,9 +26,8 @@ public function get(string $name): mixed { if ($this->has($name)) { return $this->values[$name]; - } else { - $this->throwNotFound($name); } + throw $this->notFound($name); } public function has(string $name): bool @@ -45,9 +44,8 @@ public function remove(string $name): void { if ($this->has($name)) { unset($this->values[$name]); - } else { - $this->throwNotFound($name); } + throw $this->notFound($name); } public function count(): int @@ -77,8 +75,8 @@ public function getIterator() return new \ArrayIterator($this->values); } - protected function throwNotFound(string $name): void + protected function notFound(string $name): \InvalidArgumentException { - throw new \InvalidArgumentException("Element \"$name\" not found in collection."); + return new \InvalidArgumentException("Element \"$name\" not found in collection."); } } diff --git a/src/Host/HostCollection.php b/src/Host/HostCollection.php index 37ad6ad4e..e131a0c2c 100644 --- a/src/Host/HostCollection.php +++ b/src/Host/HostCollection.php @@ -18,8 +18,8 @@ */ class HostCollection extends Collection { - protected function throwNotFound(string $name): void + protected function notFound(string $name): \InvalidArgumentException { - throw new \InvalidArgumentException("Host \"$name\" not found."); + return new \InvalidArgumentException("Host \"$name\" not found."); } } diff --git a/src/Ssh/SshClient.php b/src/Ssh/SshClient.php index eb3747d5f..c18061134 100644 --- a/src/Ssh/SshClient.php +++ b/src/Ssh/SshClient.php @@ -104,10 +104,4 @@ public function run(Host $host, string $command, array $config = []): string return $output; } - - private function parseExitStatus(Process $process): int - { - preg_match('/\[exit_code:(\d*)]/', $process->getOutput(), $match); - return (int) ($match[1] ?? -1); - } } diff --git a/src/Task/TaskCollection.php b/src/Task/TaskCollection.php index aefe79cef..87b15ade8 100644 --- a/src/Task/TaskCollection.php +++ b/src/Task/TaskCollection.php @@ -18,9 +18,9 @@ */ class TaskCollection extends Collection { - protected function throwNotFound(string $name): void + protected function notFound(string $name): \InvalidArgumentException { - throw new \InvalidArgumentException("Task `$name` not found."); + return new \InvalidArgumentException("Task `$name` not found."); } public function add(Task $task): void