Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
- tests
30 changes: 17 additions & 13 deletions src/OutputDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>' . vsprintf($message, $params) . '</error>', true);
}
Expand All @@ -78,15 +78,18 @@ public function renderIndentString(): string

/**
* @inheritDoc
* @param iterable<string>|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);
Expand All @@ -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('<info>' . vsprintf($message, $params) . '</info>', true);
}
Expand All @@ -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('<error>' . vsprintf($message, $params) . '</error>', true);
}
Expand All @@ -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('<comment>' . vsprintf($message, $params) . '</comment>', true);
}
Expand All @@ -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>|string $messages
*/
public function writeln(iterable|string $messages, int $options = 0): void
{
Expand Down
15 changes: 15 additions & 0 deletions tests/OutputDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ protected function setUp(): void
parent::setUp();
}

/**
* @return array<string, array<int, mixed>>
*/
public static function getTestData(): array
{
return [
Expand Down Expand Up @@ -90,6 +93,9 @@ public static function getTestData(): array
];
}

/**
* @param array<int, mixed> $params
*/
private function useDecoratorMethod(string $method, string $text, array $params): string
{
if (empty($params)) {
Expand All @@ -102,6 +108,9 @@ private function useDecoratorMethod(string $method, string $text, array $params)
return $this->output->fetch();
}

/**
* @param array<int, mixed> $args
*/
#[DataProvider('getTestData')]
public function testIncrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void
{
Expand All @@ -123,6 +132,9 @@ public function testIncrIndent(string $method, string $text, array $args = [], ?
$this->assertSame($this->decorator->renderIndentString() . $shouldReturn . PHP_EOL, $buffer);
}

/**
* @param array<int, mixed> $args
*/
#[DataProvider('getTestData')]
public function testDecrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void
{
Expand All @@ -140,6 +152,9 @@ public function testDecrIndent(string $method, string $text, array $args = [], ?
$this->assertSame($shouldReturn . PHP_EOL, $buffer);
}

/**
* @param array<int, mixed> $args
*/
#[DataProvider('getTestData')]
public function testResetIncr(string $method, string $text, array $args = [], ?string $shouldReturn = null): void
{
Expand Down