Skip to content

Commit e4dccd2

Browse files
committed
phpstan fixes
1 parent b23028f commit e4dccd2

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ parameters:
3737
path: src/Forms/Controls/SubmitButton.php
3838
count: 1
3939

40+
- # isSameSite() exists on the Nette\Http\Request implementation but the IRequest
41+
# interface does not declare it (it is deprecated there in favour of isFrom()).
42+
# We deliberately keep calling isSameSite() for compatibility with older nette/http
43+
# ^3.3 releases where isFrom() does not yet exist.
44+
identifier: method.notFound
45+
message: '#^Call to an undefined method Nette\\Http\\IRequest::isSameSite\(\)\.$#'
46+
path: src/Forms/Form.php
47+
count: 1
48+
4049
- # Nette\Forms\Control interface is intentionally minimal and missing common methods
4150
# (getControl, getLabel, getForm, getOption, setOption, getHtmlName, getName, getParent,
4251
# lookupPath, hasErrors, isRequired, isFilled, isDisabled, addError). In practice all
@@ -130,6 +139,7 @@ parameters:
130139
# for better type safety - the contravariance is by design.
131140
identifier: method.childParameterType
132141
message: '#^Parameter \#1 \$value \([^)]+\) of method Nette\\Forms\\Controls\\\w+::setValue\(\) should be contravariant with parameter \$value \(mixed\) of method Nette\\Forms\\(Control|Controls\\BaseControl)::setValue\(\)$#'
142+
path: src/Forms/Controls
133143

134144
- # Rules::getCallback() returns callable-array [class, method] without value type.
135145
message: '#^Method Nette\\Forms\\Rules::getCallback\(\) return type has no value type specified in iterable type array\.$#'

src/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public function __construct(string|Stringable|null $errorMessage = null)
3535

3636
$this->monitor(Presenter::class, function (Presenter $presenter): void {
3737
if (!$this->session) {
38-
$session = $presenter->getSession();
39-
assert($session instanceof Nette\Http\Session);
40-
$this->session = $session;
38+
$this->session = $presenter->getSession();
4139
$this->session->start();
4240
}
4341
});

src/Forms/Form.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,12 @@ public function allowCrossOrigin(): void
308308
public function addProtection(?string $errorMessage = null): Controls\CsrfProtection
309309
{
310310
$control = new Controls\CsrfProtection($errorMessage);
311-
$children = $this->getComponents();
312-
$first = $children ? (string) array_key_first($children) : null;
311+
$first = null;
312+
foreach ($this->getComponents() as $name => $component) {
313+
$first = (string) $name;
314+
break;
315+
}
316+
313317
$this->addComponent($control, self::ProtectorId, $first);
314318
return $control;
315319
}

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ public function renderControl(Nette\Forms\Control $control): Html
490490

491491
if ($nextTo = $control->getOption('nextTo')) {
492492
$control = $control->getForm()->getComponent($nextTo);
493+
assert($control instanceof Nette\Forms\Control);
493494
$body->class($this->getValue('control .multi'), true);
494495
goto renderControl;
495496
}

0 commit comments

Comments
 (0)