diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 06a9cf0..a62428c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.2', '8.3'] + php: ['8.2', '8.3', '8.4'] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }} diff --git a/composer.json b/composer.json index 8b8556f..07df750 100644 --- a/composer.json +++ b/composer.json @@ -12,17 +12,16 @@ "require": { "php": "^8.2", "ext-mbstring": "*", - "symfony/console": "^7.0.4" + "symfony/console": "^7.1.5" }, "require-dev": { - "ergebnis/phpstan-rules": "^2.2.0", - "illuminate/console": "^11.1.1", - "laravel/pint": "^1.15.0", - "mockery/mockery": "^1.6.11", - "pestphp/pest": "^2.34.6", - "phpstan/phpstan": "^1.10.66", - "phpstan/phpstan-strict-rules": "^1.5.2", - "symfony/var-dumper": "^7.0.4", + "illuminate/console": "^11.28.0", + "laravel/pint": "^1.18.1", + "mockery/mockery": "^1.6.12", + "pestphp/pest": "^2.36.0", + "phpstan/phpstan": "^1.12.6", + "phpstan/phpstan-strict-rules": "^1.6.1", + "symfony/var-dumper": "^7.1.5", "thecodingmachine/phpstan-strict-rules": "^1.0.0" }, "autoload": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 762ebfd..2cbd7b1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,5 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/ergebnis/phpstan-rules/rules.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon parameters: @@ -11,12 +10,3 @@ parameters: checkMissingIterableValueType: true checkGenericClassInNonGenericObjectType: true reportUnmatchedIgnoredErrors: true - - ignoreErrors: - - '#is not allowed to extend#' - - '#with default value.#' - - '#Variable method call on#' - - '#as default value#' - - '#is not final, but since the containing class is abstract, it should be#' - - '#has a nullable return type declaration.#' - - '#with a nullable type declaration.#' diff --git a/src/Actions/StyleToMethod.php b/src/Actions/StyleToMethod.php index 7524100..b17bfbf 100644 --- a/src/Actions/StyleToMethod.php +++ b/src/Actions/StyleToMethod.php @@ -96,6 +96,7 @@ public function __invoke(string|int ...$arguments): Styles return $this->__invoke(...$arguments); } + // @phpstan-ignore-next-line return $this->styles ->setStyle($this->style) ->$methodName(...array_reverse($arguments)); diff --git a/src/Components/Anchor.php b/src/Components/Anchor.php index aa29fa2..2a61731 100644 --- a/src/Components/Anchor.php +++ b/src/Components/Anchor.php @@ -4,6 +4,4 @@ namespace Termwind\Components; -final class Anchor extends Element -{ -} +final class Anchor extends Element {} diff --git a/src/Components/Element.php b/src/Components/Element.php index 98608fb..5f26a16 100644 --- a/src/Components/Element.php +++ b/src/Components/Element.php @@ -70,7 +70,7 @@ final public static function fromStyles(OutputInterface $output, array|string $c public function toString(): string { if (is_array($this->content)) { - $inheritance = new InheritStyles(); + $inheritance = new InheritStyles; $this->content = implode('', $inheritance($this->content, $this->styles)); } @@ -83,6 +83,7 @@ public function toString(): string public function __call(string $name, array $arguments): mixed { if (method_exists($this->styles, $name)) { + // @phpstan-ignore-next-line $result = $this->styles->{$name}(...$arguments); if (str_starts_with($name, 'get') || str_starts_with($name, 'has')) { diff --git a/src/Exceptions/ColorNotFound.php b/src/Exceptions/ColorNotFound.php index 0f753dd..73b4f44 100644 --- a/src/Exceptions/ColorNotFound.php +++ b/src/Exceptions/ColorNotFound.php @@ -9,6 +9,4 @@ /** * @internal */ -final class ColorNotFound extends InvalidArgumentException -{ -} +final class ColorNotFound extends InvalidArgumentException {} diff --git a/src/Exceptions/InvalidChild.php b/src/Exceptions/InvalidChild.php index cb32e99..c75fc87 100644 --- a/src/Exceptions/InvalidChild.php +++ b/src/Exceptions/InvalidChild.php @@ -9,6 +9,4 @@ /** * @internal */ -final class InvalidChild extends InvalidArgumentException -{ -} +final class InvalidChild extends InvalidArgumentException {} diff --git a/src/Exceptions/InvalidColor.php b/src/Exceptions/InvalidColor.php index d45afa1..c09e332 100644 --- a/src/Exceptions/InvalidColor.php +++ b/src/Exceptions/InvalidColor.php @@ -9,6 +9,4 @@ /** * @internal */ -final class InvalidColor extends InvalidArgumentException -{ -} +final class InvalidColor extends InvalidArgumentException {} diff --git a/src/Exceptions/InvalidStyle.php b/src/Exceptions/InvalidStyle.php index 6bcc6dd..5000f85 100644 --- a/src/Exceptions/InvalidStyle.php +++ b/src/Exceptions/InvalidStyle.php @@ -9,6 +9,4 @@ /** * @internal */ -final class InvalidStyle extends InvalidArgumentException -{ -} +final class InvalidStyle extends InvalidArgumentException {} diff --git a/src/Html/TableRenderer.php b/src/Html/TableRenderer.php index 60b73d4..81859a4 100644 --- a/src/Html/TableRenderer.php +++ b/src/Html/TableRenderer.php @@ -122,7 +122,7 @@ private function parseFoot(Node $node): void if ($child->isName('tr')) { $rows = iterator_to_array($this->parseRow($child)); if (count($rows) > 0) { - $this->table->addRow(new TableSeparator()); + $this->table->addRow(new TableSeparator); $this->table->addRows($rows); } } @@ -203,7 +203,7 @@ private function parseRow(Node $node): Iterator $border = (int) $node->getAttribute('border'); for ($i = $border; $i--; $i > 0) { - yield new TableSeparator(); + yield new TableSeparator; } } diff --git a/src/HtmlRenderer.php b/src/HtmlRenderer.php index 568c946..4f4d6b8 100644 --- a/src/HtmlRenderer.php +++ b/src/HtmlRenderer.php @@ -29,7 +29,7 @@ public function render(string $html, int $options): void */ public function parse(string $html): Components\Element { - $dom = new DOMDocument(); + $dom = new DOMDocument; if (strip_tags($html) === $html) { return Termwind::span($html); diff --git a/src/Question.php b/src/Question.php index 4d41ebd..95b201d 100644 --- a/src/Question.php +++ b/src/Question.php @@ -29,7 +29,7 @@ final class Question public function __construct(?SymfonyQuestionHelper $helper = null) { - $this->helper = $helper ?? new QuestionHelper(); + $this->helper = $helper ?? new QuestionHelper; } /** @@ -37,7 +37,7 @@ public function __construct(?SymfonyQuestionHelper $helper = null) */ public static function setStreamableInput(?StreamableInputInterface $streamableInput): void { - self::$streamableInput = $streamableInput ?? new ArgvInput(); + self::$streamableInput = $streamableInput ?? new ArgvInput; } /** @@ -45,7 +45,7 @@ public static function setStreamableInput(?StreamableInputInterface $streamableI */ public static function getStreamableInput(): StreamableInputInterface { - return self::$streamableInput ??= new ArgvInput(); + return self::$streamableInput ??= new ArgvInput; } /** @@ -73,7 +73,7 @@ public function ask(string $question, ?iterable $autocomplete = null): mixed $currentHelper = $property->isInitialized($output) ? $property->getValue($output) - : new SymfonyQuestionHelper(); + : new SymfonyQuestionHelper; $property->setValue($output, new QuestionHelper); diff --git a/src/Terminal.php b/src/Terminal.php index 23c5851..d49b941 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -21,7 +21,7 @@ final class Terminal */ public function __construct(?ConsoleTerminal $terminal = null) { - $this->terminal = $terminal ?? new ConsoleTerminal(); + $this->terminal = $terminal ?? new ConsoleTerminal; } /** diff --git a/src/Termwind.php b/src/Termwind.php index 918ee21..a2f1907 100644 --- a/src/Termwind.php +++ b/src/Termwind.php @@ -25,7 +25,7 @@ final class Termwind */ public static function renderUsing(?OutputInterface $renderer): void { - self::$renderer = $renderer ?? new ConsoleOutput(); + self::$renderer = $renderer ?? new ConsoleOutput; } /** @@ -278,7 +278,7 @@ public static function breakLine(string $styles = '', array $properties = []): C */ public static function getRenderer(): OutputInterface { - return self::$renderer ??= new ConsoleOutput(); + return self::$renderer ??= new ConsoleOutput; } /** diff --git a/src/ValueObjects/Node.php b/src/ValueObjects/Node.php index 5ef7bcf..d2482ac 100644 --- a/src/ValueObjects/Node.php +++ b/src/ValueObjects/Node.php @@ -14,9 +14,7 @@ final class Node /** * A value object with helper methods for working with DOM node. */ - public function __construct(private \DOMNode $node) - { - } + public function __construct(private \DOMNode $node) {} /** * Gets the value of the node. diff --git a/src/ValueObjects/Styles.php b/src/ValueObjects/Styles.php index 3dd1e76..48facf9 100644 --- a/src/ValueObjects/Styles.php +++ b/src/ValueObjects/Styles.php @@ -50,8 +50,7 @@ final public function __construct( private array $textModifiers = [], private array $styleModifiers = [], private array $defaultStyles = [] - ) { - } + ) {} /** * @return $this @@ -854,6 +853,7 @@ private function applyWidth(string $content): string preg_match_all("/\n+/", $content, $matches); + // @phpstan-ignore-next-line $width *= count($matches[0] ?? []) + 1; $width += mb_strlen($matches[0][0] ?? '', 'UTF-8'); @@ -998,7 +998,6 @@ private static function calcWidthFromFraction(string $fraction, array $styles, a throw new InvalidStyle(sprintf('Style [%s] is invalid.', "w-$fraction")); } - /** @@phpstan-ignore-next-line */ $width = (int) floor($width * $matches[1] / $matches[2]); $width -= ($styles['ml'] ?? 0) + ($styles['mr'] ?? 0); @@ -1030,7 +1029,7 @@ public static function getParentWidth(array $styles): int $width = count($matches) !== 3 ? (int) $parentWidth - : (int) floor($width * $matches[1] / $matches[2]); //@phpstan-ignore-line + : (int) floor($width * $matches[1] / $matches[2]); if ($maxWidth > 0) { $width = min($maxWidth, $width); @@ -1052,6 +1051,7 @@ private static function trimText(string $text, int $width): string preg_match_all(self::STYLING_REGEX, $text, $matches, PREG_OFFSET_CAPTURE); $text = rtrim(mb_strimwidth(preg_replace(self::STYLING_REGEX, '', $text) ?? '', 0, $width, '', 'UTF-8')); + // @phpstan-ignore-next-line foreach ($matches[0] ?? [] as [$part, $index]) { $text = substr($text, 0, $index).$part.substr($text, $index, null); } diff --git a/tests/Pest.php b/tests/Pest.php index f3f1803..26c1498 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -3,9 +3,9 @@ use Symfony\Component\Console\Output\BufferedOutput; use Termwind\Repositories\Styles; -use function Termwind\{renderUsing}; +use function Termwind\renderUsing; -uses()->beforeEach(fn () => renderUsing($this->output = new BufferedOutput())) +uses()->beforeEach(fn () => renderUsing($this->output = new BufferedOutput)) ->afterEach(function () { renderUsing(null); diff --git a/tests/ask.php b/tests/ask.php index 86ab7b6..b84bcec 100644 --- a/tests/ask.php +++ b/tests/ask.php @@ -52,7 +52,7 @@ $output->shouldReceive('write')->once()->with($clearLineCode); $output->shouldReceive('write')->once()->with('ne'); $output->shouldReceive('write')->once()->with($restorePositionCode); - $output->shouldReceive('getFormatter')->once()->andReturn(new NullOutputFormatter()); + $output->shouldReceive('getFormatter')->once()->andReturn(new NullOutputFormatter); ask('Question', ['one', 'two', 'three']); })->skip(! Terminal::hasSttyAvailable(), '`stty` is required to test autocomplete functionality'); diff --git a/tests/node.php b/tests/node.php index 844ed91..50d2283 100644 --- a/tests/node.php +++ b/tests/node.php @@ -25,7 +25,7 @@ }); it('gets next sibling node with empty text', function () { - $dom = new DOMDocument(); + $dom = new DOMDocument; $html = '
'; $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL); @@ -37,7 +37,7 @@ }); it('gets next sibling node with empty line', function () { - $dom = new DOMDocument(); + $dom = new DOMDocument; $html = "
\n
"; $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL); @@ -49,7 +49,7 @@ }); it('gets next sibling node with comment', function () { - $dom = new DOMDocument(); + $dom = new DOMDocument; $html = '
'; $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);