Skip to content

Commit

Permalink
feat: adds php 8.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Oct 15, 2024
1 parent e5f21ea commit 42c84e4
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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.#'
1 change: 1 addition & 0 deletions src/Actions/StyleToMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 1 addition & 3 deletions src/Components/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Termwind\Components;

final class Anchor extends Element
{
}
final class Anchor extends Element {}
3 changes: 2 additions & 1 deletion src/Components/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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')) {
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/ColorNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* @internal
*/
final class ColorNotFound extends InvalidArgumentException
{
}
final class ColorNotFound extends InvalidArgumentException {}
4 changes: 1 addition & 3 deletions src/Exceptions/InvalidChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* @internal
*/
final class InvalidChild extends InvalidArgumentException
{
}
final class InvalidChild extends InvalidArgumentException {}
4 changes: 1 addition & 3 deletions src/Exceptions/InvalidColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* @internal
*/
final class InvalidColor extends InvalidArgumentException
{
}
final class InvalidColor extends InvalidArgumentException {}
4 changes: 1 addition & 3 deletions src/Exceptions/InvalidStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
/**
* @internal
*/
final class InvalidStyle extends InvalidArgumentException
{
}
final class InvalidStyle extends InvalidArgumentException {}
4 changes: 2 additions & 2 deletions src/Html/TableRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ final class Question

public function __construct(?SymfonyQuestionHelper $helper = null)
{
$this->helper = $helper ?? new QuestionHelper();
$this->helper = $helper ?? new QuestionHelper;
}

/**
* Sets the streamable input implementation.
*/
public static function setStreamableInput(?StreamableInputInterface $streamableInput): void
{
self::$streamableInput = $streamableInput ?? new ArgvInput();
self::$streamableInput = $streamableInput ?? new ArgvInput;
}

/**
* Gets the streamable input implementation.
*/
public static function getStreamableInput(): StreamableInputInterface
{
return self::$streamableInput ??= new ArgvInput();
return self::$streamableInput ??= new ArgvInput;
}

/**
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Terminal
*/
public function __construct(?ConsoleTerminal $terminal = null)
{
$this->terminal = $terminal ?? new ConsoleTerminal();
$this->terminal = $terminal ?? new ConsoleTerminal;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Termwind.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Termwind
*/
public static function renderUsing(?OutputInterface $renderer): void
{
self::$renderer = $renderer ?? new ConsoleOutput();
self::$renderer = $renderer ?? new ConsoleOutput;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/ValueObjects/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/ValueObjects/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ final public function __construct(
private array $textModifiers = [],
private array $styleModifiers = [],
private array $defaultStyles = []
) {
}
) {}

/**
* @return $this
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$output->shouldReceive('write')->once()->with($clearLineCode);
$output->shouldReceive('write')->once()->with('<hl>ne</hl>');
$output->shouldReceive('write')->once()->with($restorePositionCode);
$output->shouldReceive('getFormatter')->once()->andReturn(new NullOutputFormatter());
$output->shouldReceive('getFormatter')->once()->andReturn(new NullOutputFormatter);

ask('<span class="bg-red ml-1">Question</span>', ['one', 'two', 'three']);
})->skip(! Terminal::hasSttyAvailable(), '`stty` is required to test autocomplete functionality');
6 changes: 3 additions & 3 deletions tests/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
});

it('gets next sibling node with empty text', function () {
$dom = new DOMDocument();
$dom = new DOMDocument;

$html = '<?xml encoding="UTF-8"><body><div></div> <div></div></body>';
$dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);
Expand All @@ -37,7 +37,7 @@
});

it('gets next sibling node with empty line', function () {
$dom = new DOMDocument();
$dom = new DOMDocument;

$html = "<?xml encoding=\"UTF-8\"><body><div></div>\n<div></div></body>";
$dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);
Expand All @@ -49,7 +49,7 @@
});

it('gets next sibling node with comment', function () {
$dom = new DOMDocument();
$dom = new DOMDocument;

$html = '<?xml encoding="UTF-8"><body><div></div><!-- Hello world --><div></div></body>';
$dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NOXMLDECL);
Expand Down

0 comments on commit 42c84e4

Please sign in to comment.