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
14 changes: 6 additions & 8 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ jobs:
max-parallel: 3
matrix:
php:
- 8.0
- 8.1
- 8.2
- 8.3
composer:
- 2
- 8.4
composer:
- 2
name: Test - php:${{ matrix.php }}; composer:${{ matrix.composer }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pcre
Expand All @@ -38,7 +36,7 @@ jobs:
run: composer test
- name: Install Composer dependencies (without dev)
run: composer install --no-progress --no-dev --no-suggest --prefer-dist --optimize-autoloader

dependabot:
needs: tests
permissions:
Expand Down Expand Up @@ -69,4 +67,4 @@ jobs:
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "Small decorator that extends Symfony OutputInterface delivered class with few options for easier to log data",
"type": "library",
"require": {
"symfony/console": "^6",
"php": ">=8.0.2"
"php": "^8.3",
"symfony/console": "^7"
},
"license": "MIT",
"authors": [
Expand Down
33 changes: 14 additions & 19 deletions src/OutputDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ class OutputDecorator implements OutputInterface
/**
* Ident for each line in left
*
* @var int
* @noinspection PropertyCanBePrivateInspection
*/
protected $indent = 0;

/**
* @var OutputInterface
*/
protected $output;
protected int $indent = 0;

/**
* OutputDecorator constructor.
*
* @param OutputInterface $originalOutput Output interface where this decorator will write
* @param OutputInterface $output Output interface where this decorator will write
*
* @noinspection PropertyCanBePrivateInspection
*/
public function __construct(OutputInterface $originalOutput)
{
$this->output = $originalOutput;
public function __construct(
protected readonly OutputInterface $output
) {
}

/**
Expand Down Expand Up @@ -81,7 +78,7 @@ public function renderIndentString(): string {
/**
* @inheritDoc
*/
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
public function write(iterable|string $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL): void
{
if ($this->indent > 0) {
$tmpMsg = '';
Expand All @@ -90,10 +87,8 @@ public function write($messages, $newline = false, $options = self::OUTPUT_NORMA
}
$messages = rtrim($tmpMsg);
}
/*if (trim($messages) == '') {
return $this->output->write(var_export([$messages, debug_backtrace(false)[1]], true), $newline, $options);
}*/
return $this->output->write($messages, $newline, $options);

$this->output->write($messages, $newline, $options);
}

/**
Expand Down Expand Up @@ -143,15 +138,15 @@ public function msg(string $message, ...$params): void
/**
* @inheritDoc
*/
public function writeln($messages, $options = 0)
public function writeln(iterable|string $messages, int $options = 0): void
{
$this->write($messages, true, $options);
}

/**
* @inheritDoc
*/
public function setVerbosity($level)
public function setVerbosity(int $level): void
{
$this->output->setVerbosity($level);
}
Expand Down Expand Up @@ -199,7 +194,7 @@ public function isDebug(): bool
/**
* @inheritDoc
*/
public function setDecorated($decorated): void
public function setDecorated(bool $decorated): void
{
$this->output->setDecorated($decorated);
}
Expand Down
23 changes: 8 additions & 15 deletions tests/OutputDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

class OutputDecoratorTest extends TestCase
{
/**
* @var OutputDecorator
*/
protected $decorator;
/**
* @var BufferedOutput
*/
protected $output;
protected OutputDecorator $decorator;
protected BufferedOutput $output;

protected function setUp(): void
{
Expand Down Expand Up @@ -93,13 +87,12 @@ public static function getTestData(): array {
];
}

protected function useDecoratorMethod(string $method, string $text, array $params): string {
private function useDecoratorMethod(string $method, string $text, array $params): string {
if (empty($params)) {
$this->decorator->$method($text);
} else {
$args = $params;
array_unshift($args, $text);
call_user_func_array([$this->decorator, $method], $args);
$args = [$text, ...$params];
$this->decorator->$method(...$args);
}

return $this->output->fetch();
Expand All @@ -108,7 +101,7 @@ protected function useDecoratorMethod(string $method, string $text, array $param
/**
* @dataProvider getTestData
*/
public function testIncrIndent(string $method, string $text, array $args = [], $shouldReturn = null): void {
public function testIncrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void {
if ($shouldReturn === null) {
$shouldReturn = $text;
}
Expand All @@ -130,7 +123,7 @@ public function testIncrIndent(string $method, string $text, array $args = [], $
/**
* @dataProvider getTestData
*/
public function testDecrIndent(string $method, string $text, array $args = [], $shouldReturn = null): void
public function testDecrIndent(string $method, string $text, array $args = [], ?string $shouldReturn = null): void
{
if ($shouldReturn === null) {
$shouldReturn = $text;
Expand All @@ -149,7 +142,7 @@ public function testDecrIndent(string $method, string $text, array $args = [], $
/**
* @dataProvider getTestData
*/
public function testResetIncr(string $method, string $text, array $args = [], $shouldReturn = null): void {
public function testResetIncr(string $method, string $text, array $args = [], ?string $shouldReturn = null): void {
if ($shouldReturn === null) {
$shouldReturn = $text;
}
Expand Down