Skip to content

Commit

Permalink
cs nullable typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 12, 2021
1 parent 4ede7e3 commit 9264864
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/Tracy/BlueScreenPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class BlueScreenPanel
{
public static function initialize(BlueScreen $blueScreen = null): void
public static function initialize(?BlueScreen $blueScreen = null): void
{
$blueScreen = $blueScreen ?? Tracy\Debugger::getBlueScreen();
$blueScreen->addPanel([self::class, 'renderError']);
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Tracy/LattePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class LattePanel implements Tracy\IBarPanel
private $name;


public static function initialize(Engine $latte, string $name = null, Tracy\Bar $bar = null): void
public static function initialize(Engine $latte, ?string $name = null, ?Tracy\Bar $bar = null): void
{
$bar = $bar ?? Tracy\Debugger::getBar();
$bar->addPanel(new self($latte, $name));
}


public function __construct(Engine $latte, string $name = null)
public function __construct(Engine $latte, ?string $name = null)
{
$this->name = $name;
$latte->probe = function (Template $template): void {
Expand Down
12 changes: 6 additions & 6 deletions src/Latte/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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 (!preg_match('#^[a-z_=]\w*(?:[.:-]\w+)*$#iD', $name)) {
throw new \LogicException("Invalid tag name '$name'.");
Expand Down Expand Up @@ -142,7 +142,7 @@ public function setFunctions(array $names)
* Compiles tokens to PHP file
* @param Token[] $tokens
*/
public function compile(array $tokens, string $className, string $comment = null, bool $strictMode = false): string
public function compile(array $tokens, string $className, ?string $comment = null, bool $strictMode = false): string
{
$code = "<?php\n\n"
. ($strictMode ? "declare(strict_types=1);\n\n" : '')
Expand Down Expand Up @@ -331,7 +331,7 @@ public function addMethod(
string $body,
string $arguments = '',
string $returns = '',
string $comment = null
?string $comment = null
): void {
$body = trim($body);
$this->methods[$name] = compact('body', 'arguments', 'returns', 'comment');
Expand Down Expand Up @@ -622,7 +622,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 @@ -650,7 +650,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 @@ -837,7 +837,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 @@ -51,7 +51,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
8 changes: 4 additions & 4 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 Expand Up @@ -124,7 +124,7 @@ public function getNotation(): string
/**
* @param string[] $names
*/
public function closest(array $names, callable $condition = null): ?self
public function closest(array $names, ?callable $condition = null): ?self
{
$node = $this->parentNode;
while ($node && (
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 @@ -36,7 +36,7 @@ class PhpWriter
private $line;


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 @@ -50,7 +50,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 @@ -145,7 +145,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 @@ -157,7 +157,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->namedArgumentsPass($tokens);
Expand Down Expand Up @@ -187,7 +187,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 @@ -94,7 +94,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
{
$template = $this->createTemplate($name, $this->processParams($params));
$template->global->coreCaptured = false;
Expand All @@ -107,7 +107,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));
$template->global->coreCaptured = true;
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
4 changes: 2 additions & 2 deletions src/Latte/Macros/BlockMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function macroBlockEnd(MacroNode $node, PhpWriter $writer): string
}


private function addBlock(MacroNode $node, string $layer = null): Block
private function addBlock(MacroNode $node, ?string $layer = null): Block
{
$data = $node->data;
if ($layer === Template::LAYER_SNIPPET
Expand All @@ -564,7 +564,7 @@ private function addBlock(MacroNode $node, string $layer = null): Block
}


private function extractMethod(MacroNode $node, Block $block, string $params = null): void
private function extractMethod(MacroNode $node, Block $block, ?string $params = null): void
{
if (preg_match('#\$|n:#', $node->content)) {
$node->content = '<?php extract(' . ($node->name === 'block' && $node->closest(['embed']) ? 'end($this->varStack)' : '$this->params') . ');'
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 tag '$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 @@ -76,7 +76,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 @@ -130,7 +130,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
6 changes: 3 additions & 3 deletions src/Latte/Runtime/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CachingIterator extends \CachingIterator implements \Countable
/**
* @param array|\Traversable|\stdClass|mixed $iterator
*/
public function __construct($iterator, self $parent = null)
public function __construct($iterator, ?self $parent = null)
{
if (is_array($iterator) || $iterator instanceof \stdClass) {
$iterator = new \ArrayIterator($iterator);
Expand All @@ -66,7 +66,7 @@ public function __construct($iterator, self $parent = null)
/**
* 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 @@ -75,7 +75,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
4 changes: 2 additions & 2 deletions src/Latte/Runtime/FilterInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class FilterInfo
public $contentType;


public function __construct(string $contentType = null)
public function __construct(?string $contentType = null)
{
$this->contentType = $contentType;
}


public function validate(array $contentTypes, string $name = null): void
public function validate(array $contentTypes, ?string $name = null): void
{
if (!in_array($this->contentType, $contentTypes, true)) {
$name = $name ? " |$name" : $name;
Expand Down
12 changes: 6 additions & 6 deletions src/Latte/Runtime/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,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 @@ -442,7 +442,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 @@ -535,7 +535,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 @@ -557,7 +557,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 Expand Up @@ -752,7 +752,7 @@ public static function batch($list, int $length, $rest = null): \Generator
* @param mixed[] $array
* @return mixed[]
*/
public static function sort(array $array, \Closure $callback = null): array
public static function sort(array $array, ?\Closure $callback = null): array
{
$callback ? uasort($array, $callback) : asort($array);
return $array;
Expand Down Expand Up @@ -847,7 +847,7 @@ public static function last($value)
* @param string|array $value
* @return string|array
*/
public static function slice($value, int $start, int $length = null, bool $preserveKeys = false)
public static function slice($value, int $start, ?int $length = null, bool $preserveKeys = false)
{
return is_array($value)
? array_slice($value, $start, $length, $preserveKeys)
Expand Down
8 changes: 4 additions & 4 deletions src/Latte/Runtime/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getReferenceType(): ?string
* Renders template.
* @internal
*/
public function render(string $block = null): void
public function render(?string $block = null): void
{
$level = ob_get_level();
try {
Expand All @@ -185,7 +185,7 @@ public function render(string $block = null): void
}


private function doRender(string $block = null): bool
private function doRender(?string $block = null): bool
{
if ($this->parentName === null && isset($this->global->coreParentFinder)) {
$this->parentName = ($this->global->coreParentFinder)($this);
Expand Down Expand Up @@ -260,7 +260,7 @@ public function createTemplate(string $name, array $params, string $referenceTyp
* @param string|\Closure|null $mod content-type name or modifier closure
* @internal
*/
public function renderToContentType($mod, string $block = null): void
public function renderToContentType($mod, ?string $block = null): void
{
$this->filter(
function () use ($block) { $this->render($block); },
Expand Down Expand Up @@ -405,7 +405,7 @@ public function capture(callable $function): string
/**
* @param int|string $staticId
*/
private function initBlockLayer($staticId, int $destId = null): void
private function initBlockLayer($staticId, ?int $destId = null): void
{
$destId = $destId ?? $staticId;
$this->blocks[$destId] = [];
Expand Down
Loading

0 comments on commit 9264864

Please sign in to comment.