Skip to content

Commit 3dfa903

Browse files
committed
phpstan fixes
1 parent cdf59b0 commit 3dfa903

8 files changed

Lines changed: 19 additions & 7 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"require-dev": {
2929
"nette/tester": "^2.6",
30+
"nette/caching": "^3.2",
3031
"nette/di": "^3.2",
3132
"nette/forms": "^3.2",
3233
"nette/robot-loader": "^4.0",

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ parameters:
2424

2525
# === Application ===
2626

27+
# isSameSite() was removed from the IRequest interface in newer nette/http (replaced by isFrom()), but isFrom()/FetchSite don't exist in older versions still allowed by composer.json (^3.3.2). The runtime call works on the concrete Request in all versions.
28+
-
29+
identifier: method.notFound
30+
message: '#Call to an undefined method Nette\\Http\\IRequest::isSameSite\(\)#'
31+
path: src/Application/UI/AccessPolicy.php
32+
2733
# PresenterFactory: defensive type checks after regex validation — always true but kept for safety
2834
-
2935
path: src/Application/PresenterFactory.php

src/Bridges/ApplicationLatte/Nodes/ControlNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public static function create(Tag $tag): static
4747
$start = $stream->getIndex();
4848
$node->args = $tag->parser->parseArguments();
4949
$start -= $stream->getIndex();
50-
$depth = $wrap = null;
50+
$depth = 0;
51+
$wrap = null;
5152
for (; $start < 0; $start++) {
5253
$token = $stream->peek($start);
5354
match (true) {

src/Bridges/ApplicationLatte/Nodes/LinkBaseNode.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ public function &getIterator(): \Generator
5757

5858
public static function applyLinkBasePass(TemplateNode $node): void
5959
{
60-
$base = NodeHelpers::findFirst($node, fn(Node $node) => $node instanceof self)?->base;
61-
if ($base === null) {
60+
$found = NodeHelpers::findFirst($node, fn(Node $node) => $node instanceof self);
61+
if (!$found instanceof self) {
6262
return;
6363
}
6464

65+
$base = $found->base;
6566
(new NodeTraverser)->traverse($node, function (Node $link) use ($base) {
6667
if ($link instanceof LinkNode) {
6768
if ($link->destination instanceof StringNode && $base instanceof StringNode) {

src/Bridges/ApplicationLatte/Nodes/LinkNode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static function create(Tag $tag): ?static
4343
$node->mode = $tag->name;
4444

4545
if ($tag->isNAttribute()) {
46+
assert($tag->htmlElement !== null);
4647
// move at the beginning
4748
$node->position = $tag->position;
4849
array_unshift($tag->htmlElement->attributes->children, $node);

src/Bridges/ApplicationLatte/Nodes/SnippetNode.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function create(Tag $tag, TemplateParser $parser): \Generator
6262
}
6363

6464
if ($tag->isNAttribute()) {
65+
assert($tag->htmlElement !== null);
6566
if ($tag->prefix !== $tag::PrefixNone) {
6667
throw new CompileException("Use n:snippet instead of {$tag->getNotation()}", $tag->position);
6768

@@ -96,8 +97,8 @@ public function print(PrintContext $context): string
9697
}
9798

9899
if ($this->htmlElement) {
100+
$inner = $this->htmlElement->content;
99101
try {
100-
$inner = $this->htmlElement->content;
101102
$this->htmlElement->content = new AuxiliaryNode(fn() => $this->printContent($context, $inner));
102103
return $this->content->print($context);
103104
} finally {

src/Bridges/ApplicationLatte/Nodes/TemplatePrintNode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public static function printClass(array $params, string $parentClass): void
4646
$bp->printCode($code);
4747

4848
if ($control instanceof UI\Control) {
49-
$file = dirname((new \ReflectionClass($control))->getFileName()) . '/' . $class->getName() . '.php';
49+
$controlFile = (new \ReflectionClass($control))->getFileName()
50+
?: throw new \LogicException('Cannot determine file of class ' . $control::class . '.');
51+
$file = dirname($controlFile) . '/' . $class->getName() . '.php';
5052
if (file_exists($file)) {
5153
echo "unsaved, file {$bp->clickableFile($file)} already exists";
5254
} else {

src/Bridges/ApplicationLatte/SnippetRuntime.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ final class SnippetRuntime
2929
private array $stack = [];
3030
private int $nestingLevel = 0;
3131
private bool $renderingSnippets = false;
32-
33-
private ?\stdClass $payload;
32+
private \stdClass $payload;
3433

3534

3635
public function __construct(

0 commit comments

Comments
 (0)