From b1e5211418db6613645a2468ac989c7fe2fef408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimondas=20Rimkevi=C4=8Dius=20=28aka=20MekDrop=29?= Date: Fri, 27 Jun 2025 00:59:13 +0300 Subject: [PATCH] Bumped min PHP version to 8.3 Resolves #30 --- .github/workflows/on_pull_request.yml | 14 +++++------- composer.json | 4 ++-- src/OutputDecorator.php | 33 ++++++++++++--------------- tests/OutputDecoratorTest.php | 23 +++++++------------ 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/.github/workflows/on_pull_request.yml b/.github/workflows/on_pull_request.yml index 5fe96c3..07735fc 100644 --- a/.github/workflows/on_pull_request.yml +++ b/.github/workflows/on_pull_request.yml @@ -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 @@ -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: @@ -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 }} diff --git a/composer.json b/composer.json index 28addcf..e2d67a4 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/OutputDecorator.php b/src/OutputDecorator.php index bfa9d8d..609f036 100644 --- a/src/OutputDecorator.php +++ b/src/OutputDecorator.php @@ -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 + ) { } /** @@ -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 = ''; @@ -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); } /** @@ -143,7 +138,7 @@ 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); } @@ -151,7 +146,7 @@ public function writeln($messages, $options = 0) /** * @inheritDoc */ - public function setVerbosity($level) + public function setVerbosity(int $level): void { $this->output->setVerbosity($level); } @@ -199,7 +194,7 @@ public function isDebug(): bool /** * @inheritDoc */ - public function setDecorated($decorated): void + public function setDecorated(bool $decorated): void { $this->output->setDecorated($decorated); } diff --git a/tests/OutputDecoratorTest.php b/tests/OutputDecoratorTest.php index 89422e1..fab776c 100644 --- a/tests/OutputDecoratorTest.php +++ b/tests/OutputDecoratorTest.php @@ -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 { @@ -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(); @@ -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; } @@ -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; @@ -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; }