diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e12dadd..3023e1d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dependency-version: [prefer-lowest, prefer-stable] + dependency-version: [prefer-stable] name: PHPStan ${{ matrix.dependency-version }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5dd7d46..bd895d6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,8 +7,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.0', '8.1', '8.2', '8.3'] - dependency-version: [prefer-lowest, prefer-stable] + php: ['8.1', '8.2', '8.3', '8.4'] + dependency-version: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.parallel }} diff --git a/composer.json b/composer.json index a1dc78d..b20d5d7 100644 --- a/composer.json +++ b/composer.json @@ -10,20 +10,19 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-mbstring": "*", - "symfony/console": "^5.3.0|^6.0.0" + "symfony/console": "^6.4.12" }, "require-dev": { - "ergebnis/phpstan-rules": "^1.0.", - "illuminate/console": "^8.0|^9.0|^10.0", - "illuminate/support": "^8.0|^9.0|^10.0", - "laravel/pint": "^1.0.0", - "pestphp/pest": "^1.21.0", - "pestphp/pest-plugin-mock": "^1.0", - "phpstan/phpstan": "^1.4.6", - "phpstan/phpstan-strict-rules": "^1.1.0", - "symfony/var-dumper": "^5.2.7|^6.0.0", + "illuminate/console": "^10.48.22", + "illuminate/support": "^10.48.22", + "laravel/pint": "^1.18.1", + "pestphp/pest": "^2", + "pestphp/pest-plugin-mock": "2.0.0", + "phpstan/phpstan": "^1.12.6", + "phpstan/phpstan-strict-rules": "^1.6.1", + "symfony/var-dumper": "^6.4.11", "thecodingmachine/phpstan-strict-rules": "^1.0.0" }, "autoload": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 33719d8..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,10 +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#' 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 9ec8fbf..9becdb8 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/Functions.php b/src/Functions.php index 20cec63..9b073b2 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -14,7 +14,7 @@ /** * Sets the renderer implementation. */ - function renderUsing(OutputInterface|null $renderer): void + function renderUsing(?OutputInterface $renderer): void { Termwind::renderUsing($renderer); } @@ -26,7 +26,7 @@ function renderUsing(OutputInterface|null $renderer): void * * @param (Closure(Styles $renderable, string|int ...$arguments): Styles)|null $callback */ - function style(string $name, Closure $callback = null): Style + function style(string $name, ?Closure $callback = null): Style { return StyleRepository::create($name, $callback); } @@ -58,7 +58,7 @@ function terminal(): Terminal * * @param iterable|null $autocomplete */ - function ask(string $question, iterable $autocomplete = null): mixed + function ask(string $question, ?iterable $autocomplete = null): mixed { return (new Question)->ask($question, $autocomplete); } 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 289f866..f20682b 100644 --- a/src/Question.php +++ b/src/Question.php @@ -27,9 +27,9 @@ final class Question */ private SymfonyQuestionHelper $helper; - public function __construct(SymfonyQuestionHelper $helper = null) + 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|null $streamableInput): void { - self::$streamableInput = $streamableInput ?? new ArgvInput(); + self::$streamableInput = $streamableInput ?? new ArgvInput; } /** @@ -45,7 +45,7 @@ public static function setStreamableInput(StreamableInputInterface|null $streama */ public static function getStreamableInput(): StreamableInputInterface { - return self::$streamableInput ??= new ArgvInput(); + return self::$streamableInput ??= new ArgvInput; } /** @@ -53,7 +53,7 @@ public static function getStreamableInput(): StreamableInputInterface * * @param iterable|null $autocomplete */ - public function ask(string $question, iterable $autocomplete = null): mixed + public function ask(string $question, ?iterable $autocomplete = null): mixed { $html = (new HtmlRenderer)->parse($question)->toString(); @@ -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/Repositories/Styles.php b/src/Repositories/Styles.php index 5518a95..8c1d6f6 100644 --- a/src/Repositories/Styles.php +++ b/src/Repositories/Styles.php @@ -23,7 +23,7 @@ final class Styles * * @param (Closure(StylesValueObject $element, string|int ...$arguments): StylesValueObject)|null $callback */ - public static function create(string $name, Closure $callback = null): Style + public static function create(string $name, ?Closure $callback = null): Style { self::$storage[$name] = $style = new Style( $callback ?? static fn (StylesValueObject $styles) => $styles diff --git a/src/Terminal.php b/src/Terminal.php index 6b74885..d49b941 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -19,9 +19,9 @@ final class Terminal /** * Creates a new terminal instance. */ - public function __construct(ConsoleTerminal $terminal = null) + 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 0ce1b51..6dcaaed 100644 --- a/src/Termwind.php +++ b/src/Termwind.php @@ -25,7 +25,7 @@ final class Termwind */ public static function renderUsing(OutputInterface|null $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 8e388ae..d42ca79 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 d7d98c8..b29ee05 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,7 +853,7 @@ private function applyWidth(string $content): string preg_match_all("/\n+/", $content, $matches); - $width *= count($matches[0] ?? []) + 1; + $width *= count($matches[0] ?? []) + 1; // @phpstan-ignore-line $width += mb_strlen($matches[0][0] ?? '', 'UTF-8'); if ($length <= $width) { @@ -940,7 +939,7 @@ private function applyStyling(string $content): string /** * Get the length of the text provided without the styling tags. */ - public function getLength(string $text = null): int + public function getLength(?string $text = null): int { return mb_strlen(preg_replace( self::STYLING_REGEX, @@ -998,7 +997,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 +1028,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 +1050,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 223d831..5aa27da 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -4,9 +4,9 @@ use Termwind\HtmlRenderer; 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/a.php b/tests/a.php index 5d1e374..fa458da 100644 --- a/tests/a.php +++ b/tests/a.php @@ -1,7 +1,5 @@ link text'); 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/br.php b/tests/br.php index 6e33e68..3546991 100644 --- a/tests/br.php +++ b/tests/br.php @@ -1,7 +1,5 @@ '); 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); diff --git a/tests/span.php b/tests/span.php index 9bf2a09..1554095 100644 --- a/tests/span.php +++ b/tests/span.php @@ -1,7 +1,5 @@ text'); diff --git a/tests/strong.php b/tests/strong.php index 4c917d5..3b50b43 100644 --- a/tests/strong.php +++ b/tests/strong.php @@ -1,7 +1,5 @@ text');