This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

0
vendor/nunomaduro/collision/LICENSE.md vendored Normal file → Executable file
View File

View File

@@ -15,26 +15,26 @@
],
"require": {
"php": "^8.1.0",
"filp/whoops": "^2.15.3",
"nunomaduro/termwind": "^1.15.1",
"symfony/console": "^6.3.4"
"filp/whoops": "^2.17.0",
"nunomaduro/termwind": "^1.17.0",
"symfony/console": "^6.4.17"
},
"conflict": {
"laravel/framework": ">=11.0.0"
},
"require-dev": {
"brianium/paratest": "^7.3.0",
"laravel/framework": "^10.28.0",
"laravel/pint": "^1.13.3",
"laravel/sail": "^1.25.0",
"laravel/sanctum": "^3.3.1",
"laravel/tinker": "^2.8.2",
"nunomaduro/larastan": "^2.6.4",
"orchestra/testbench-core": "^8.13.0",
"pestphp/pest": "^2.23.2",
"phpunit/phpunit": "^10.4.1",
"sebastian/environment": "^6.0.1",
"spatie/laravel-ignition": "^2.3.1"
"brianium/paratest": "^7.4.8",
"laravel/framework": "^10.48.29",
"laravel/pint": "^1.21.2",
"laravel/sail": "^1.41.0",
"laravel/sanctum": "^3.3.3",
"laravel/tinker": "^2.10.1",
"nunomaduro/larastan": "^2.10.0",
"orchestra/testbench-core": "^8.35.0",
"pestphp/pest": "^2.36.0",
"phpunit/phpunit": "^10.5.36",
"sebastian/environment": "^6.1.0",
"spatie/laravel-ignition": "^2.9.1"
},
"autoload-dev": {
"psr-4": {

View File

@@ -48,7 +48,7 @@ class CollisionServiceProvider extends ServiceProvider
$solutionsRepository = new IgnitionSolutionsRepository($solutionProviderRepository);
} else {
$solutionsRepository = new NullSolutionsRepository();
$solutionsRepository = new NullSolutionsRepository;
}
$writer = new Writer($solutionsRepository);

View File

@@ -195,7 +195,7 @@ class TestCommand extends Command
if ($this->option('ansi')) {
$arguments[] = '--colors=always';
} elseif ($this->option('no-ansi')) { // @phpstan-ignore-line
} elseif ($this->option('no-ansi')) {
$arguments[] = '--colors=never';
} elseif ((new Console)->hasColorSupport()) {
$arguments[] = '--colors=always';
@@ -281,7 +281,7 @@ class TestCommand extends Command
"--runner=\Illuminate\Testing\ParallelRunner",
], $options);
$inputDefinition = new InputDefinition();
$inputDefinition = new InputDefinition;
Options::setInputDefinition($inputDefinition);
$input = new ArgvInput($options, $inputDefinition);
@@ -379,7 +379,7 @@ class TestCommand extends Command
$vars = [];
foreach ((new Parser())->parse($content) as $entry) {
foreach ((new Parser)->parse($content) as $entry) {
$vars[] = $entry->getName();
}

View File

@@ -11,6 +11,4 @@ use RuntimeException;
/**
* @internal
*/
final class NotSupportedYetException extends RuntimeException implements RenderlessEditor, RenderlessTrace
{
}
final class NotSupportedYetException extends RuntimeException implements RenderlessEditor, RenderlessTrace {}

View File

@@ -11,6 +11,4 @@ use RuntimeException;
/**
* @internal
*/
final class RequirementsException extends RuntimeException implements RenderlessEditor, RenderlessTrace
{
}
final class RequirementsException extends RuntimeException implements RenderlessEditor, RenderlessTrace {}

View File

@@ -31,7 +31,7 @@ final class ConfigureIO
*/
public static function of(InputInterface $input, Output $output): void
{
$application = new Application();
$application = new Application;
$reflector = new ReflectionObject($application);
$method = $reflector->getMethod('configureIO');
$method->setAccessible(true);

View File

@@ -98,19 +98,19 @@ final class DefaultPrinter
{
$this->output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, $colors);
ConfigureIO::of(new ArgvInput(), $this->output);
ConfigureIO::of(new ArgvInput, $this->output);
self::$verbose = $this->output->isVerbose();
$this->style = new Style($this->output);
$this->state = new State();
$this->state = new State;
}
/**
* If the printer instances should be compact.
*/
public static function compact(bool $value = null): bool
public static function compact(?bool $value = null): bool
{
if (! is_null($value)) {
self::$compact = $value;
@@ -122,7 +122,7 @@ final class DefaultPrinter
/**
* If the printer instances should profile.
*/
public static function profile(bool $value = null): bool
public static function profile(?bool $value = null): bool
{
if (! is_null($value)) {
self::$profile = $value;
@@ -165,7 +165,7 @@ final class DefaultPrinter
$test = $event->test();
if (! $test instanceof TestMethod) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
if (! $this->state->existsInTestCase($event->test())) {
@@ -196,7 +196,7 @@ final class DefaultPrinter
$test = $event->test();
if (! $test instanceof TestMethod) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
if ($this->state->testCaseHasChanged($test)) {

View File

@@ -55,7 +55,7 @@ final class Style
public function __construct(ConsoleOutputInterface $output)
{
if (! $output instanceof ConsoleOutput) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
$this->terminal = terminal();
@@ -173,7 +173,7 @@ final class Style
array_map(function (TestResult $testResult): void {
if (! $testResult->throwable instanceof Throwable) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
renderUsing($this->output);
@@ -327,7 +327,7 @@ final class Style
*/
public function writeError(Throwable $throwable): void
{
$writer = (new Writer())->setOutput($this->output);
$writer = (new Writer)->setOutput($this->output);
$throwable = new TestException($throwable, $this->output->isVerbose());

View File

@@ -303,7 +303,7 @@ if (class_exists(Version::class) && (int) Version::series() >= 10) {
if ($shouldRegister) {
self::$registered = true;
Facade::instance()->registerSubscriber(new self());
Facade::instance()->registerSubscriber(new self);
}
}
}

View File

@@ -63,7 +63,7 @@ final class TestResult
/**
* Creates a new TestResult instance.
*/
private function __construct(string $id, string $testCaseName, string $description, string $type, string $icon, string $compactIcon, string $color, string $compactColor, Throwable $throwable = null)
private function __construct(string $id, string $testCaseName, string $description, string $type, string $icon, string $compactIcon, string $color, string $compactColor, ?Throwable $throwable = null)
{
$this->id = $id;
$this->testCaseName = $testCaseName;
@@ -114,10 +114,10 @@ final class TestResult
/**
* Creates a new test from the given test case.
*/
public static function fromTestCase(Test $test, string $type, Throwable $throwable = null): self
public static function fromTestCase(Test $test, string $type, ?Throwable $throwable = null): self
{
if (! $test instanceof TestMethod) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
if (is_subclass_of($test->className(), HasPrintableTestCaseName::class)) {
@@ -142,10 +142,10 @@ final class TestResult
/**
* Creates a new test from the given Pest Parallel Test Case.
*/
public static function fromPestParallelTestCase(Test $test, string $type, Throwable $throwable = null): self
public static function fromPestParallelTestCase(Test $test, string $type, ?Throwable $throwable = null): self
{
if (! $test instanceof TestMethod) {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
if (is_subclass_of($test->className(), HasPrintableTestCaseName::class)) {

View File

@@ -102,7 +102,7 @@ class ConsoleColor
} elseif ($this->isValidStyle($s)) {
$sequences[] = $this->styleSequence($s);
} else {
throw new ShouldNotHappen();
throw new ShouldNotHappen;
}
}
@@ -218,7 +218,10 @@ class ConsoleColor
preg_match(self::COLOR256_REGEXP, $style, $matches);
// @phpstan-ignore-next-line
$type = $matches[1] === 'bg_' ? self::BACKGROUND : self::FOREGROUND;
// @phpstan-ignore-next-line
$value = $matches[2];
return "$type;5;$value";

View File

@@ -7,6 +7,4 @@ namespace NunoMaduro\Collision\Contracts;
/**
* @internal
*/
interface RenderlessEditor
{
}
interface RenderlessEditor {}

View File

@@ -7,6 +7,4 @@ namespace NunoMaduro\Collision\Contracts;
/**
* @internal
*/
interface RenderlessTrace
{
}
interface RenderlessTrace {}

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace NunoMaduro\Collision\Contracts;
use Spatie\Ignition\Contracts\Solution;
use Spatie\ErrorSolutions\Contracts\Solution;
use Throwable;
/**

View File

@@ -36,7 +36,7 @@ final class Coverage
*/
public static function isAvailable(): bool
{
$runtime = new Runtime();
$runtime = new Runtime;
if (! $runtime->canCollectCodeCoverage()) {
return false;
@@ -60,7 +60,7 @@ final class Coverage
*/
public static function usingXdebug(): bool
{
return (new Runtime())->hasXdebug();
return (new Runtime)->hasXdebug();
}
/**

View File

@@ -22,9 +22,9 @@ final class Handler extends AbstractHandler
/**
* Creates an instance of the Handler.
*/
public function __construct(Writer $writer = null)
public function __construct(?Writer $writer = null)
{
$this->writer = $writer ?: new Writer();
$this->writer = $writer ?: new Writer;
}
/**

View File

@@ -77,9 +77,9 @@ final class Highlighter
/**
* Creates an instance of the Highlighter.
*/
public function __construct(ConsoleColor $color = null, bool $UTF8 = true)
public function __construct(?ConsoleColor $color = null, bool $UTF8 = true)
{
$this->color = $color ?: new ConsoleColor();
$this->color = $color ?: new ConsoleColor;
foreach (self::DEFAULT_THEME as $name => $styles) {
if (! $this->color->hasTheme($name)) {
@@ -249,7 +249,7 @@ final class Highlighter
return $lines;
}
private function lineNumbers(array $lines, int $markLine = null): string
private function lineNumbers(array $lines, ?int $markLine = null): string
{
$lineStrlen = strlen((string) ((int) array_key_last($lines) + 1));
$lineStrlen = $lineStrlen < self::WIDTH ? self::WIDTH : $lineStrlen;

View File

@@ -27,10 +27,10 @@ final class Provider
/**
* Creates a new instance of the Provider.
*/
public function __construct(RunInterface $run = null, Handler $handler = null)
public function __construct(?RunInterface $run = null, ?Handler $handler = null)
{
$this->run = $run ?: new Run();
$this->handler = $handler ?: new Handler();
$this->run = $run ?: new Run;
$this->handler = $handler ?: new Handler;
}
/**

View File

@@ -76,15 +76,15 @@ final class Writer
* Creates an instance of the writer.
*/
public function __construct(
SolutionsRepository $solutionsRepository = null,
OutputInterface $output = null,
ArgumentFormatter $argumentFormatter = null,
Highlighter $highlighter = null
?SolutionsRepository $solutionsRepository = null,
?OutputInterface $output = null,
?ArgumentFormatter $argumentFormatter = null,
?Highlighter $highlighter = null
) {
$this->solutionsRepository = $solutionsRepository ?: new NullSolutionsRepository();
$this->output = $output ?: new ConsoleOutput();
$this->argumentFormatter = $argumentFormatter ?: new ArgumentFormatter();
$this->highlighter = $highlighter ?: new Highlighter();
$this->solutionsRepository = $solutionsRepository ?: new NullSolutionsRepository;
$this->output = $output ?: new ConsoleOutput;
$this->argumentFormatter = $argumentFormatter ?: new ArgumentFormatter;
$this->highlighter = $highlighter ?: new Highlighter;
}
public function write(Inspector $inspector): void

0
vendor/nunomaduro/termwind/LICENSE.md vendored Normal file → Executable file
View File

View File

@@ -1,33 +0,0 @@
# Well documented Makefiles
DEFAULT_GOAL := help
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ [Docker]
start: ## Spin up the container
docker-compose up -d
stop: ## Shut down the containers
docker-compose down
build: ## Build all docker images
docker-compose build
##@ [Application]
composer: ## Run composer commands. Specify the command e.g. via "make composer ARGS="install|update|require <dependency>"
docker-compose run --rm app composer $(ARGS)
lint: ## Run the Linter
docker-compose run --rm app ./vendor/bin/pint -v
test-lint: ## Run the Linter Test
docker-compose run --rm app ./vendor/bin/pint --test -v
test-types: ## Run the PHPStan analysis
docker-compose run --rm app ./vendor/bin/phpstan analyse --ansi
test-unit: ## Run the Pest Test Suite
docker-compose run --rm app ./vendor/bin/pest --colors=always
test: ## Run the tests. Apply arguments via make test ARGS="--init"
make test-lint && make test-types && make test-unit

View File

@@ -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.15"
},
"require-dev": {
"ergebnis/phpstan-rules": "^1.0.",
"illuminate/console": "^8.0|^9.0",
"illuminate/support": "^8.0|^9.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.24",
"illuminate/support": "^10.48.24",
"laravel/pint": "^1.18.2",
"pestphp/pest": "^2.36.0",
"pestphp/pest-plugin-mock": "2.0.0",
"phpstan/phpstan": "^1.12.11",
"phpstan/phpstan-strict-rules": "^1.6.1",
"symfony/var-dumper": "^6.4.15",
"thecodingmachine/phpstan-strict-rules": "^1.0.0"
},
"autoload": {

View File

@@ -1,13 +0,0 @@
version: '3'
services:
app:
image: termwind-docker
container_name: termwind-docker
stdin_open: true
tty: true
build:
context: .
dockerfile: docker/Dockerfile
volumes:
- .:/usr/src/app

View File

@@ -1,11 +0,0 @@
FROM php:8.2-cli-alpine
# INSTALL AND UPDATE COMPOSER
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN composer self-update
WORKDIR /usr/src/app
COPY . .
# INSTALL YOUR DEPENDENCIES
RUN composer install --prefer-dist

7
vendor/nunomaduro/termwind/pint.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"rules": {
"yoda_style": false,
"nullable_type_declaration": false,
"nullable_type_declaration_for_default_null_value": false
}
}

View File

@@ -5,10 +5,18 @@ require_once __DIR__.'/vendor/autoload.php';
use function Termwind\render;
render(<<<'HTML'
<div class="mx-2 my-1">
<div class="flex space-x-1">
<span class="flex-1 truncate">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Sunt illo et nisi omnis porro at, mollitia harum quas esse, aperiam dolorem ab recusandae fugiat nesciunt doloribus rem eaque nostrum itaque.</span>
<span class="text-green">DONE</span>
</div>
<div class="ml-2">
<pre>
──, ──,
/ \ / / / / \─│/ /
│─/\─/│─/ \─/│─/│──/\─/│─/\─/ │──/│──/
</pre>
<div class="px-1 bg-green-300 text-black">by ⚙️ Configured</div>
<div class="px-1 mt-1 bg-blue-300 text-black">{{ $version }}</div>
<em class="ml-1">
Create portable PHP CLI applications w/ PHP Micro
</em>
</div>
HTML);

View File

@@ -59,8 +59,6 @@ final class StyleToMethod
/**
* Converts the given style to a method name.
*
* @return Styles
*/
public function __invoke(string|int ...$arguments): Styles
{
@@ -98,6 +96,7 @@ final class StyleToMethod
return $this->__invoke(...$arguments);
}
// @phpstan-ignore-next-line
return $this->styles
->setStyle($this->style)
->$methodName(...array_reverse($arguments));

View File

@@ -4,6 +4,4 @@ declare(strict_types=1);
namespace Termwind\Components;
final class Anchor extends Element
{
}
final class Anchor extends Element {}

View File

@@ -70,7 +70,7 @@ abstract class Element
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 @@ abstract class Element
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')) {

View File

@@ -9,6 +9,4 @@ use InvalidArgumentException;
/**
* @internal
*/
final class ColorNotFound extends InvalidArgumentException
{
}
final class ColorNotFound extends InvalidArgumentException {}

View File

@@ -9,6 +9,4 @@ use InvalidArgumentException;
/**
* @internal
*/
final class InvalidChild extends InvalidArgumentException
{
}
final class InvalidChild extends InvalidArgumentException {}

View File

@@ -9,6 +9,4 @@ use InvalidArgumentException;
/**
* @internal
*/
final class InvalidColor extends InvalidArgumentException
{
}
final class InvalidColor extends InvalidArgumentException {}

View File

@@ -9,6 +9,4 @@ use InvalidArgumentException;
/**
* @internal
*/
final class InvalidStyle extends InvalidArgumentException
{
}
final class InvalidStyle extends InvalidArgumentException {}

View File

@@ -14,7 +14,7 @@ if (! function_exists('Termwind\renderUsing')) {
/**
* Sets the renderer implementation.
*/
function renderUsing(OutputInterface|null $renderer): void
function renderUsing(?OutputInterface $renderer): void
{
Termwind::renderUsing($renderer);
}
@@ -24,9 +24,9 @@ if (! function_exists('Termwind\style')) {
/**
* Creates a new style.
*
* @param (Closure(Styles $renderable, string|int ...$arguments): Styles)|null $callback
* @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 @@ if (! function_exists('Termwind\ask')) {
*
* @param iterable<array-key, string>|null $autocomplete
*/
function ask(string $question, iterable $autocomplete = null): mixed
function ask(string $question, ?iterable $autocomplete = null): mixed
{
return (new Question)->ask($question, $autocomplete);
}

View File

@@ -173,7 +173,6 @@ final class CodeRenderer
* Splits tokens into lines.
*
* @param array<int, array{0: string, 1: string}> $tokens
* @param int $startLine
* @return array<int, array<int, array{0: string, 1: non-empty-string}>>
*/
private function splitToLines(array $tokens, int $startLine): array
@@ -228,8 +227,6 @@ final class CodeRenderer
* Prepends line numbers into lines.
*
* @param array<int, string> $lines
* @param int $markLine
* @return string
*/
private function lineNumbers(array $lines, int $markLine): string
{

View File

@@ -122,7 +122,7 @@ final class TableRenderer
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 @@ final class TableRenderer
$border = (int) $node->getAttribute('border');
for ($i = $border; $i--; $i > 0) {
yield new TableSeparator();
yield new TableSeparator;
}
}

View File

@@ -29,7 +29,7 @@ final class HtmlRenderer
*/
public function parse(string $html): Components\Element
{
$dom = new DOMDocument();
$dom = new DOMDocument;
if (strip_tags($html) === $html) {
return Termwind::span($html);

View File

@@ -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 @@ final class Question
*/
public static function setStreamableInput(StreamableInputInterface|null $streamableInput): void
{
self::$streamableInput = $streamableInput ?? new ArgvInput();
self::$streamableInput = $streamableInput ?? new ArgvInput;
}
/**
@@ -45,7 +45,7 @@ final class Question
*/
public static function getStreamableInput(): StreamableInputInterface
{
return self::$streamableInput ??= new ArgvInput();
return self::$streamableInput ??= new ArgvInput;
}
/**
@@ -53,7 +53,7 @@ final class Question
*
* @param iterable<array-key, string>|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 @@ final class Question
$currentHelper = $property->isInitialized($output)
? $property->getValue($output)
: new SymfonyQuestionHelper();
: new SymfonyQuestionHelper;
$property->setValue($output, new QuestionHelper);

View File

@@ -21,10 +21,9 @@ final class Styles
/**
* Creates a new style from the given arguments.
*
* @param (Closure(StylesValueObject $element, string|int ...$arguments): StylesValueObject)|null $callback
* @return Style
* @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

View File

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

View File

@@ -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 @@ final class Termwind
*/
public static function getRenderer(): OutputInterface
{
return self::$renderer ??= new ConsoleOutput();
return self::$renderer ??= new ConsoleOutput;
}
/**

View File

@@ -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.
@@ -34,7 +32,7 @@ final class Node
public function getChildNodes(): Generator
{
foreach ($this->node->childNodes as $node) {
yield new static($node);
yield new self($node);
}
}
@@ -106,7 +104,7 @@ final class Node
$node = $this->node;
while ($node = $node->previousSibling) {
$node = new static($node);
$node = new self($node);
if ($node->isEmpty()) {
$node = $node->node;
@@ -121,7 +119,7 @@ final class Node
$node = $node->node;
}
return is_null($node) ? null : new static($node);
return is_null($node) ? null : new self($node);
}
/**
@@ -132,7 +130,7 @@ final class Node
$node = $this->node;
while ($node = $node->nextSibling) {
$node = new static($node);
$node = new self($node);
if ($node->isEmpty()) {
$node = $node->node;
@@ -147,7 +145,7 @@ final class Node
$node = $node->node;
}
return is_null($node) ? null : new static($node);
return is_null($node) ? null : new self($node);
}
/**

View File

@@ -16,7 +16,7 @@ final class Style
/**
* Creates a new value object instance.
*
* @param Closure(Styles $styles, string|int ...$argument): Styles $callback
* @param Closure(Styles $styles, string|int ...$argument): Styles $callback
*/
public function __construct(private Closure $callback, private string $color = '')
{

View File

@@ -15,6 +15,7 @@ use Termwind\Enums\Color;
use Termwind\Exceptions\ColorNotFound;
use Termwind\Exceptions\InvalidStyle;
use Termwind\Repositories\Styles as StyleRepository;
use function Termwind\terminal;
/**
@@ -49,11 +50,9 @@ final class Styles
private array $textModifiers = [],
private array $styleModifiers = [],
private array $defaultStyles = []
) {
}
) {}
/**
* @param Element $element
* @return $this
*/
public function setElement(Element $element): self
@@ -854,7 +853,7 @@ final class Styles
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 @@ final class Styles
/**
* 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 @@ final class Styles
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 @@ final class Styles
$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 @@ final class Styles
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);
}