Skip to content

Commit f7d123e

Browse files
committed
strict fixes
1 parent b2ed5b5 commit f7d123e

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
100100
if (empty($var)) {
101101
return '[]';
102102

103-
} elseif ($level > $this->maxDepth || in_array($var, $parents ?? [], true)) {
103+
} elseif ($level > $this->maxDepth || in_array($var, $parents, true)) {
104104
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
105105
}
106106

@@ -160,7 +160,7 @@ private function dumpObject($var, array $parents, int $level): string
160160
$arr = (array) $var;
161161
$space = str_repeat($this->indentation, $level);
162162

163-
if ($level > $this->maxDepth || in_array($var, $parents ?? [], true)) {
163+
if ($level > $this->maxDepth || in_array($var, $parents, true)) {
164164
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
165165
}
166166

src/PhpGenerator/Extractor.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public function extractAll(): PhpFile
166166
$phpFile = new PhpFile;
167167
$namespace = '';
168168
$visitor = new class extends PhpParser\NodeVisitorAbstract {
169+
public $callback;
170+
171+
169172
public function enterNode(Node $node)
170173
{
171174
return ($this->callback)($node);
@@ -177,7 +180,9 @@ public function enterNode(Node $node)
177180
return PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
178181
}
179182
match (true) {
180-
$node instanceof Node\Stmt\DeclareDeclare && $node->key->name === 'strict_types' => $phpFile->setStrictTypes((bool) $node->value->value),
183+
$node instanceof Node\Stmt\DeclareDeclare
184+
&& $node->key->name === 'strict_types'
185+
&& $node->value instanceof Node\Scalar\LNumber => $phpFile->setStrictTypes((bool) $node->value->value),
181186
$node instanceof Node\Stmt\Namespace_ => $namespace = $node->name?->toString(),
182187
$node instanceof Node\Stmt\Use_ => $this->addUseToNamespace($node, $phpFile->addNamespace($namespace)),
183188
$node instanceof Node\Stmt\Class_ => $class = $this->addClassToFile($phpFile, $node),
@@ -385,7 +390,7 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
385390
{
386391
$function->setReturnReference($node->returnsByRef());
387392
$function->setReturnType($node->getReturnType() ? $this->toPhp($node->getReturnType()) : null);
388-
foreach ($node->params as $item) {
393+
foreach ($node->getParams() as $item) {
389394
$param = $function->addParameter($item->var->name);
390395
$param->setType($item->type ? $this->toPhp($item->type) : null);
391396
$param->setReference($item->byRef);
@@ -398,8 +403,8 @@ private function setupFunction(GlobalFunction|Method $function, Node\FunctionLik
398403
}
399404

400405
$this->addCommentAndAttributes($function, $node);
401-
if ($node->stmts) {
402-
$function->setBody($this->getReformattedContents($node->stmts, 2));
406+
if ($node->getStmts()) {
407+
$function->setBody($this->getReformattedContents($node->getStmts(), 2));
403408
}
404409
}
405410

src/PhpGenerator/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ final class Helpers
3737
'endforeach' => 1, 'declare' => 1, 'enddeclare' => 1, 'as' => 1, 'try' => 1, 'catch' => 1, 'finally' => 1,
3838
'throw' => 1, 'use' => 1, 'insteadof' => 1, 'global' => 1, 'var' => 1, 'unset' => 1, 'isset' => 1, 'empty' => 1,
3939
'continue' => 1, 'goto' => 1, 'function' => 1, 'const' => 1, 'return' => 1, 'print' => 1, 'yield' => 1, 'list' => 1,
40-
'switch' => 1, 'endswitch' => 1, 'case' => 1, 'default' => 1, 'break' => 1, 'array' => 1, 'callable' => 1,
40+
'switch' => 1, 'endswitch' => 1, 'case' => 1, 'default' => 1, 'break' => 1,
4141
'extends' => 1, 'implements' => 1, 'namespace' => 1, 'trait' => 1, 'interface' => 1, 'class' => 1, '__CLASS__' => 1,
4242
'__TRAIT__' => 1, '__FUNCTION__' => 1, '__METHOD__' => 1, '__LINE__' => 1, '__FILE__' => 1, '__DIR__' => 1,
43-
'__NAMESPACE__' => 1, 'fn' => 1, 'match' => 1, 'enum' => 1, 'static' => 1, 'abstract' => 1, 'final' => 1,
43+
'__NAMESPACE__' => 1, 'fn' => 1, 'match' => 1, 'enum' => 1, 'abstract' => 1, 'final' => 1,
4444
'private' => 1, 'protected' => 1, 'public' => 1, 'readonly' => 1,
4545

4646
// additional reserved class names

0 commit comments

Comments
 (0)