Skip to content

Commit

Permalink
cs nullable typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 4, 2022
1 parent f37f671 commit 59d2521
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/Latte/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -593,7 +593,7 @@ public function closeMacro(
string $args = '',
string $modifiers = '',
bool $isRightmost = false,
string $nPrefix = null
?string $nPrefix = null
): MacroNode {
$node = $this->macroNode;

Expand Down Expand Up @@ -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}}?" : '')
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Compiler/HtmlNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Latte/Compiler/MacroNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Compiler/MacroTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Latte/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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); });
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Loaders/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Loaders/StringLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Macros/MacroSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'.");
Expand Down
6 changes: 3 additions & 3 deletions src/Latte/Runtime/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`.');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Latte/Runtime/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Runtime/FilterInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FilterInfo
public $contentType;


public function __construct(string $contentType = null)
public function __construct(?string $contentType = null)
{
$this->contentType = $contentType;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Latte/Runtime/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Runtime/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

0 comments on commit 59d2521

Please sign in to comment.