From 59d25212c0a8d4dcb13da93462a7483e68586435 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Dec 2021 18:23:20 +0100 Subject: [PATCH] cs nullable typehints --- src/Latte/Compiler/Compiler.php | 8 ++++---- src/Latte/Compiler/HtmlNode.php | 2 +- src/Latte/Compiler/MacroNode.php | 6 +++--- src/Latte/Compiler/MacroTokens.php | 2 +- src/Latte/Compiler/PhpWriter.php | 10 +++++----- src/Latte/Engine.php | 4 ++-- src/Latte/Loaders/FileLoader.php | 2 +- src/Latte/Loaders/StringLoader.php | 2 +- src/Latte/Macros/MacroSet.php | 2 +- src/Latte/Runtime/Blueprint.php | 6 +++--- src/Latte/Runtime/CachingIterator.php | 4 ++-- src/Latte/Runtime/FilterInfo.php | 2 +- src/Latte/Runtime/Filters.php | 8 ++++---- src/Latte/Runtime/Template.php | 2 +- src/Latte/exceptions.php | 4 ++-- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Latte/Compiler/Compiler.php b/src/Latte/Compiler/Compiler.php index 4957e8c15..0559b2562 100644 --- a/src/Latte/Compiler/Compiler.php +++ b/src/Latte/Compiler/Compiler.php @@ -103,7 +103,7 @@ class Compiler * Adds new macro with Macro flags. * @return static */ - public function addMacro(string $name, Macro $macro, int $flags = null) + public function addMacro(string $name, Macro $macro, ?int $flags = null) { if (!isset($this->flags[$name])) { $this->flags[$name] = $flags ?: Macro::DEFAULT_FLAGS; @@ -565,7 +565,7 @@ public function openMacro( string $args = '', string $modifiers = '', bool $isRightmost = false, - string $nPrefix = null + ?string $nPrefix = null ): MacroNode { $node = $this->expandMacro($name, $args, $modifiers, $nPrefix); if ($node->empty) { @@ -593,7 +593,7 @@ public function closeMacro( string $args = '', string $modifiers = '', bool $isRightmost = false, - string $nPrefix = null + ?string $nPrefix = null ): MacroNode { $node = $this->macroNode; @@ -780,7 +780,7 @@ public function writeAttrsMacro(string $html): void * Expands macro and returns node & code. * @internal */ - public function expandMacro(string $name, string $args, string $modifiers = '', string $nPrefix = null): MacroNode + public function expandMacro(string $name, string $args, string $modifiers = '', ?string $nPrefix = null): MacroNode { if (empty($this->macros[$name])) { $hint = (($t = Helpers::getSuggestion(array_keys($this->macros), $name)) ? ", did you mean {{$t}}?" : '') diff --git a/src/Latte/Compiler/HtmlNode.php b/src/Latte/Compiler/HtmlNode.php index 3376817fe..28ac9f9a2 100644 --- a/src/Latte/Compiler/HtmlNode.php +++ b/src/Latte/Compiler/HtmlNode.php @@ -48,7 +48,7 @@ class HtmlNode public $innerMarker; - public function __construct(string $name, self $parentNode = null) + public function __construct(string $name, ?self $parentNode = null) { $this->name = $name; $this->parentNode = $parentNode; diff --git a/src/Latte/Compiler/MacroNode.php b/src/Latte/Compiler/MacroNode.php index e5c1298e5..2c8693d2f 100644 --- a/src/Latte/Compiler/MacroNode.php +++ b/src/Latte/Compiler/MacroNode.php @@ -91,9 +91,9 @@ public function __construct( string $name, string $args = '', string $modifiers = '', - self $parentNode = null, - HtmlNode $htmlNode = null, - string $prefix = null + ?self $parentNode = null, + ?HtmlNode $htmlNode = null, + ?string $prefix = null ) { $this->macro = $macro; $this->name = $name; diff --git a/src/Latte/Compiler/MacroTokens.php b/src/Latte/Compiler/MacroTokens.php index 474a5d333..11fd57173 100644 --- a/src/Latte/Compiler/MacroTokens.php +++ b/src/Latte/Compiler/MacroTokens.php @@ -72,7 +72,7 @@ public function parse(string $s): array * @param string|array{string, int, int} $val * @return static */ - public function append($val, int $position = null) + public function append($val, ?int $position = null) { if ($val != null) { // intentionally @ array_splice( diff --git a/src/Latte/Compiler/PhpWriter.php b/src/Latte/Compiler/PhpWriter.php index f500bc38b..125424ff4 100644 --- a/src/Latte/Compiler/PhpWriter.php +++ b/src/Latte/Compiler/PhpWriter.php @@ -33,7 +33,7 @@ class PhpWriter private $functions = []; - public static function using(MacroNode $node, Compiler $compiler = null): self + public static function using(MacroNode $node, ?Compiler $compiler = null): self { $me = new static($node->tokenizer, null, $node->context); $me->modifiers = &$node->modifiers; @@ -46,7 +46,7 @@ public static function using(MacroNode $node, Compiler $compiler = null): self /** * @param array{string, mixed}|null $context */ - public function __construct(MacroTokens $tokens, string $modifiers = null, array $context = null) + public function __construct(MacroTokens $tokens, ?string $modifiers = null, ?array $context = null) { $this->tokens = $tokens; $this->modifiers = $modifiers; @@ -138,7 +138,7 @@ public function formatModifiers(string $var, bool $isContent = false): string /** * Formats macro arguments to PHP code. (It advances tokenizer to the end as a side effect.) */ - public function formatArgs(MacroTokens $tokens = null): string + public function formatArgs(?MacroTokens $tokens = null): string { $tokens = $this->preprocess($tokens); $tokens = $this->quotingPass($tokens); @@ -150,7 +150,7 @@ public function formatArgs(MacroTokens $tokens = null): string /** * Formats macro arguments to PHP array. (It advances tokenizer to the end as a side effect.) */ - public function formatArray(MacroTokens $tokens = null): string + public function formatArray(?MacroTokens $tokens = null): string { $tokens = $this->preprocess($tokens); $tokens = $this->expandCastPass($tokens); @@ -174,7 +174,7 @@ public function formatWord(string $s): string /** * Preprocessor for tokens. (It advances tokenizer to the end as a side effect.) */ - public function preprocess(MacroTokens $tokens = null): MacroTokens + public function preprocess(?MacroTokens $tokens = null): MacroTokens { $tokens = $tokens ?? $this->tokens; $this->validateTokens($tokens); diff --git a/src/Latte/Engine.php b/src/Latte/Engine.php index dde6e62b4..1669717e8 100644 --- a/src/Latte/Engine.php +++ b/src/Latte/Engine.php @@ -81,7 +81,7 @@ public function __construct() * Renders template to output. * @param object|mixed[] $params */ - public function render(string $name, $params = [], string $block = null): void + public function render(string $name, $params = [], ?string $block = null): void { $this->createTemplate($name, $this->processParams($params)) ->render($block); @@ -92,7 +92,7 @@ public function render(string $name, $params = [], string $block = null): void * Renders template to string. * @param object|mixed[] $params */ - public function renderToString(string $name, $params = [], string $block = null): string + public function renderToString(string $name, $params = [], ?string $block = null): string { $template = $this->createTemplate($name, $this->processParams($params)); return $template->capture(function () use ($template, $block) { $template->render($block); }); diff --git a/src/Latte/Loaders/FileLoader.php b/src/Latte/Loaders/FileLoader.php index 4a9f6a274..b87d036c8 100644 --- a/src/Latte/Loaders/FileLoader.php +++ b/src/Latte/Loaders/FileLoader.php @@ -23,7 +23,7 @@ class FileLoader implements Latte\Loader protected $baseDir; - public function __construct(string $baseDir = null) + public function __construct(?string $baseDir = null) { $this->baseDir = $baseDir ? $this->normalizePath("$baseDir/") : null; } diff --git a/src/Latte/Loaders/StringLoader.php b/src/Latte/Loaders/StringLoader.php index dc96099ac..5b3a5d391 100644 --- a/src/Latte/Loaders/StringLoader.php +++ b/src/Latte/Loaders/StringLoader.php @@ -26,7 +26,7 @@ class StringLoader implements Latte\Loader /** * @param string[] $templates */ - public function __construct(array $templates = null) + public function __construct(?array $templates = null) { $this->templates = $templates; } diff --git a/src/Latte/Macros/MacroSet.php b/src/Latte/Macros/MacroSet.php index cedfd0cc7..2396bad25 100644 --- a/src/Latte/Macros/MacroSet.php +++ b/src/Latte/Macros/MacroSet.php @@ -39,7 +39,7 @@ public function __construct(Latte\Compiler $compiler) * @param string|callable|null $end * @param string|callable|null $attr */ - public function addMacro(string $name, $begin, $end = null, $attr = null, int $flags = null): self + public function addMacro(string $name, $begin, $end = null, $attr = null, ?int $flags = null): self { if (!$begin && !$end && !$attr) { throw new \InvalidArgumentException("At least one argument must be specified for macro '$name'."); diff --git a/src/Latte/Runtime/Blueprint.php b/src/Latte/Runtime/Blueprint.php index 181113df6..6e095a1c2 100644 --- a/src/Latte/Runtime/Blueprint.php +++ b/src/Latte/Runtime/Blueprint.php @@ -21,7 +21,7 @@ class Blueprint { use Latte\Strict; - public function printClass(Template $template, string $name = null): void + public function printClass(Template $template, ?string $name = null): void { if (!class_exists(Php\ClassType::class)) { throw new \LogicException('Nette PhpGenerator is required to print template, install package `nette/php-generator`.'); @@ -75,7 +75,7 @@ public function printVars(array $vars): void /** * @param mixed[] $props */ - public function addProperties(Php\ClassType $class, array $props, bool $native = null): void + public function addProperties(Php\ClassType $class, array $props, ?bool $native = null): void { $printer = new Php\Printer; $native = $native ?? (PHP_VERSION_ID >= 70400); @@ -129,7 +129,7 @@ private function printType(?string $type, bool $nullable, ?Php\PhpNamespace $nam /** * @param Closure|GlobalFunction|Method $function */ - public function printParameters($function, Php\PhpNamespace $namespace = null): string + public function printParameters($function, ?Php\PhpNamespace $namespace = null): string { $params = []; $list = $function->getParameters(); diff --git a/src/Latte/Runtime/CachingIterator.php b/src/Latte/Runtime/CachingIterator.php index 3d8849cac..30d39429d 100644 --- a/src/Latte/Runtime/CachingIterator.php +++ b/src/Latte/Runtime/CachingIterator.php @@ -60,7 +60,7 @@ public function __construct($iterator) /** * Is the current element the first one? */ - public function isFirst(int $width = null): bool + public function isFirst(?int $width = null): bool { return $this->counter === 1 || ($width && $this->counter !== 0 && (($this->counter - 1) % $width) === 0); } @@ -69,7 +69,7 @@ public function isFirst(int $width = null): bool /** * Is the current element the last one? */ - public function isLast(int $width = null): bool + public function isLast(?int $width = null): bool { return !$this->hasNext() || ($width && ($this->counter % $width) === 0); } diff --git a/src/Latte/Runtime/FilterInfo.php b/src/Latte/Runtime/FilterInfo.php index 91b2fb1a7..7017dca8a 100644 --- a/src/Latte/Runtime/FilterInfo.php +++ b/src/Latte/Runtime/FilterInfo.php @@ -23,7 +23,7 @@ class FilterInfo public $contentType; - public function __construct(string $contentType = null) + public function __construct(?string $contentType = null) { $this->contentType = $contentType; } diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index 069d301ce..a3f850fb0 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -350,7 +350,7 @@ function ($m) use (&$strip) { /** * Output buffering handler for spacelessHtml. */ - public static function spacelessHtmlHandler(string $s, int $phase = null): string + public static function spacelessHtmlHandler(string $s, ?int $phase = null): string { static $strip; $left = $right = ''; @@ -432,7 +432,7 @@ public static function repeat(FilterInfo $info, $s, int $count): string * Date/time formatting. * @param string|int|\DateTimeInterface|\DateInterval $time */ - public static function date($time, string $format = null): ?string + public static function date($time, ?string $format = null): ?string { if ($time == null) { // intentionally == return null; @@ -507,7 +507,7 @@ public static function replaceRe(string $subject, string $pattern, string $repla * The data: URI generator. * @return string plain text */ - public static function dataStream(string $data, string $type = null): string + public static function dataStream(string $data, ?string $type = null): string { if ($type === null) { $type = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); @@ -529,7 +529,7 @@ public static function breaklines($s): Html /** * Returns a part of string. */ - public static function substring($s, int $start, int $length = null): string + public static function substring($s, int $start, ?int $length = null): string { $s = (string) $s; if ($length === null) { diff --git a/src/Latte/Runtime/Template.php b/src/Latte/Runtime/Template.php index e50f296d5..1f8e1199e 100644 --- a/src/Latte/Runtime/Template.php +++ b/src/Latte/Runtime/Template.php @@ -154,7 +154,7 @@ public function getReferenceType(): ?string * Renders template. * @internal */ - public function render(string $block = null): void + public function render(?string $block = null): void { $this->prepare(); diff --git a/src/Latte/exceptions.php b/src/Latte/exceptions.php index 2b0c9b798..0d0488971 100644 --- a/src/Latte/exceptions.php +++ b/src/Latte/exceptions.php @@ -25,7 +25,7 @@ class CompileException extends \Exception public $sourceLine; - public function setSource(string $code, ?int $line, string $name = null): self + public function setSource(string $code, ?int $line, ?string $name = null): self { $this->sourceCode = $code; $this->sourceLine = $line; @@ -55,7 +55,7 @@ class RegexpException extends \Exception ]; - public function __construct(?string $message, int $code = null) + public function __construct(?string $message, ?int $code = null) { parent::__construct($message ?: (self::MESSAGES[$code] ?? 'Unknown error'), $code); }