Skip to content

Commit 02d645e

Browse files
committed
cs
fixed PHPStan errors - CsrfProtection: removed redundant assert (getSession() already returns Session) - Form: use foreach instead of array_key_first() on iterable getComponents() - Form: replaced deprecated isSameSite() with isFrom() (declared on IRequest) - DefaultFormRenderer: assert Control type after reassignment in render loop
1 parent f11fdde commit 02d645e

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎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)