🔧
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -4,6 +4,4 @@ declare(strict_types=1);
|
||||
|
||||
namespace Termwind\Components;
|
||||
|
||||
final class Anchor extends Element
|
||||
{
|
||||
}
|
||||
final class Anchor extends Element {}
|
||||
|
||||
@@ -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')) {
|
||||
|
||||
@@ -9,6 +9,4 @@ use InvalidArgumentException;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ColorNotFound extends InvalidArgumentException
|
||||
{
|
||||
}
|
||||
final class ColorNotFound extends InvalidArgumentException {}
|
||||
|
||||
@@ -9,6 +9,4 @@ use InvalidArgumentException;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidChild extends InvalidArgumentException
|
||||
{
|
||||
}
|
||||
final class InvalidChild extends InvalidArgumentException {}
|
||||
|
||||
@@ -9,6 +9,4 @@ use InvalidArgumentException;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidColor extends InvalidArgumentException
|
||||
{
|
||||
}
|
||||
final class InvalidColor extends InvalidArgumentException {}
|
||||
|
||||
@@ -9,6 +9,4 @@ use InvalidArgumentException;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidStyle extends InvalidArgumentException
|
||||
{
|
||||
}
|
||||
final class InvalidStyle extends InvalidArgumentException {}
|
||||
|
||||
8
vendor/nunomaduro/termwind/src/Functions.php
vendored
8
vendor/nunomaduro/termwind/src/Functions.php
vendored
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
12
vendor/nunomaduro/termwind/src/Question.php
vendored
12
vendor/nunomaduro/termwind/src/Question.php
vendored
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
4
vendor/nunomaduro/termwind/src/Terminal.php
vendored
4
vendor/nunomaduro/termwind/src/Terminal.php
vendored
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
4
vendor/nunomaduro/termwind/src/Termwind.php
vendored
4
vendor/nunomaduro/termwind/src/Termwind.php
vendored
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 = '')
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user