From a5213fe13d45aacab25c0b54cbaf1a888ee9bdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87a=C4=9Fda=C5=9F=20SAYGILI?= Date: Wed, 10 Apr 2024 00:26:20 +0300 Subject: [PATCH 1/2] test: refactor system/CLI/BaseCommand.php --- phpstan-baseline.php | 20 -------------------- system/CLI/BaseCommand.php | 10 +++++++--- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 9c5c98a51e45..1bec8d83965b 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -261,26 +261,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/BaseModel.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/system/CLI/BaseCommand.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:__get\\(\\) return type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/BaseCommand.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:call\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/BaseCommand.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:getPad\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/CLI/BaseCommand.php', -]; $ignoreErrors[] = [ 'message' => '#^Accessing offset \'ANSICON\' directly on \\$_SERVER is discouraged\\.$#', 'count' => 1, diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index 1b273846bd74..ffba81c33637 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -108,6 +108,8 @@ abstract public function run(array $params); /** * Can be used by a command to run other commands. * + * @param array $params + * * @return int|void * * @throws ReflectionException @@ -140,7 +142,7 @@ public function showHelp() { CLI::write(lang('CLI.helpUsage'), 'yellow'); - if (! empty($this->usage)) { + if (isset($this->usage)) { $usage = $this->usage; } else { $usage = $this->name; @@ -152,7 +154,7 @@ public function showHelp() CLI::write($this->setPad($usage, 0, 0, 2)); - if (! empty($this->description)) { + if (isset($this->description)) { CLI::newLine(); CLI::write(lang('CLI.helpDescription'), 'yellow'); CLI::write($this->setPad($this->description, 0, 0, 2)); @@ -194,6 +196,8 @@ public function setPad(string $item, int $max, int $extra = 2, int $indent = 0): /** * Get pad for $key => $value array output * + * @param array $array + * * @deprecated Use setPad() instead. * * @codeCoverageIgnore @@ -212,7 +216,7 @@ public function getPad(array $array, int $pad): int /** * Makes it simple to access our protected properties. * - * @return array|Commands|LoggerInterface|string|null + * @return Commands|list|LoggerInterface|string|null */ public function __get(string $key) { From 2a6591aaa4f17e0348fa2458d546505d9964622c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87a=C4=9Fda=C5=9F=20SAYGILI?= Date: Wed, 10 Apr 2024 14:23:41 +0300 Subject: [PATCH 2/2] Fix doc type ordering in BaseCommand.php following PHPStan guidelines and PR review. --- system/CLI/BaseCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index ffba81c33637..86ba504feaa6 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -216,7 +216,7 @@ public function getPad(array $array, int $pad): int /** * Makes it simple to access our protected properties. * - * @return Commands|list|LoggerInterface|string|null + * @return array|Commands|LoggerInterface|string|null */ public function __get(string $key) {