diff --git a/.github/workflows/on_pull_request.yml b/.github/workflows/on_pull_request.yml index 2cc318c..c5d649e 100644 --- a/.github/workflows/on_pull_request.yml +++ b/.github/workflows/on_pull_request.yml @@ -34,6 +34,8 @@ jobs: run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader - name: PHP CodeSniffer run: composer phpcs + - name: PHPStan + run: composer phpstan - name: PHPUnit run: composer test - name: Install Composer dependencies (without dev) diff --git a/composer.json b/composer.json index 312fef6..c81bdfe 100644 --- a/composer.json +++ b/composer.json @@ -31,11 +31,13 @@ ], "require-dev": { "phpunit/phpunit": "^12", - "squizlabs/php_codesniffer": "^3.10" + "squizlabs/php_codesniffer": "^3.10", + "phpstan/phpstan": "^2" }, "scripts": { "test": "phpunit --testdox", "phpcs": "phpcs --standard=PSR12 src/ tests/", - "phpcbf": "phpcbf --standard=PSR12 src/ tests/" + "phpcbf": "phpcbf --standard=PSR12 src/ tests/", + "phpstan": "phpstan analyse" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..1494f51 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: max + paths: + - src + - tests diff --git a/src/OutputDecorator.php b/src/OutputDecorator.php index 7e3ab8c..84c6234 100644 --- a/src/OutputDecorator.php +++ b/src/OutputDecorator.php @@ -59,9 +59,9 @@ public function resetIndent(): void * Prints fatal message * * @param string $message Message to print - * @param mixed ...$params Params for parsing message + * @param string|int|float|bool|null ...$params Params for parsing message */ - public function fatal(string $message, ...$params): void + public function fatal(string $message, string|int|float|bool|null ...$params): void { $this->write('' . vsprintf($message, $params) . '', true); } @@ -78,15 +78,18 @@ public function renderIndentString(): string /** * @inheritDoc + * @param iterable|string $messages */ public function write(iterable|string $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL): void { if ($this->indent > 0) { $tmpMsg = ''; - foreach (explode(PHP_EOL, $messages) as $line) { - $tmpMsg .= $this->renderIndentString() . $line . PHP_EOL; + if (is_string($messages)) { + foreach (explode(PHP_EOL, $messages) as $line) { + $tmpMsg .= $this->renderIndentString() . $line . PHP_EOL; + } + $messages = rtrim($tmpMsg); } - $messages = rtrim($tmpMsg); } $this->output->write($messages, $newline, $options); @@ -96,9 +99,9 @@ public function write(iterable|string $messages, bool $newline = false, int $opt * Prints success message * * @param string $message Message to print - * @param mixed ...$params Params for parsing message + * @param string|int|float|bool|null ...$params Params for parsing message */ - public function success(string $message, ...$params): void + public function success(string $message, string|int|float|bool|null ...$params): void { $this->write('' . vsprintf($message, $params) . '', true); } @@ -107,9 +110,9 @@ public function success(string $message, ...$params): void * Prints error message * * @param string $message Message to print - * @param mixed ...$params Params for parsing message + * @param string|int|float|bool|null ...$params Params for parsing message */ - public function error(string $message, ...$params): void + public function error(string $message, string|int|float|bool|null ...$params): void { $this->write('' . vsprintf($message, $params) . '', true); } @@ -118,9 +121,9 @@ public function error(string $message, ...$params): void * Prints info message * * @param string $message Message to print - * @param mixed ...$params Params for parsing message + * @param string|int|float|bool|null ...$params Params for parsing message */ - public function info(string $message, ...$params): void + public function info(string $message, string|int|float|bool|null ...$params): void { $this->write('' . vsprintf($message, $params) . '', true); } @@ -129,15 +132,16 @@ public function info(string $message, ...$params): void * Prints simple message * * @param string $message Message to print - * @param mixed ...$params Params for parsing message + * @param string|int|float|bool|null ...$params Params for parsing message */ - public function msg(string $message, ...$params): void + public function msg(string $message, string|int|float|bool|null ...$params): void { $this->write(vsprintf($message, $params), true); } /** * @inheritDoc + * @param iterable|string $messages */ public function writeln(iterable|string $messages, int $options = 0): void { diff --git a/tests/OutputDecoratorTest.php b/tests/OutputDecoratorTest.php index 065d6e9..d6a4dfd 100644 --- a/tests/OutputDecoratorTest.php +++ b/tests/OutputDecoratorTest.php @@ -20,6 +20,9 @@ protected function setUp(): void parent::setUp(); } + /** + * @return array> + */ public static function getTestData(): array { return [ @@ -90,6 +93,9 @@ public static function getTestData(): array ]; } + /** + * @param array $params + */ private function useDecoratorMethod(string $method, string $text, array $params): string { if (empty($params)) { @@ -102,6 +108,9 @@ private function useDecoratorMethod(string $method, string $text, array $params) return $this->output->fetch(); } + /** + * @param array $args + */ #[DataProvider('getTestData')] public function testIncrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void { @@ -123,6 +132,9 @@ public function testIncrIndent(string $method, string $text, array $args = [], ? $this->assertSame($this->decorator->renderIndentString() . $shouldReturn . PHP_EOL, $buffer); } + /** + * @param array $args + */ #[DataProvider('getTestData')] public function testDecrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void { @@ -140,6 +152,9 @@ public function testDecrIndent(string $method, string $text, array $args = [], ? $this->assertSame($shouldReturn . PHP_EOL, $buffer); } + /** + * @param array $args + */ #[DataProvider('getTestData')] public function testResetIncr(string $method, string $text, array $args = [], ?string $shouldReturn = null): void {