Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1115f9

Browse files
minor #42537 [Form] Fix return types in form builder (Tobion)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] Fix return types in form builder | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | Fix return types incompatibilities found by psalm in #42511 > Error: The declared return type 'Symfony\Component\EventDispatcher\EventDispatcherInterface' for Symfony\Component\Form\ButtonBuilder::getEventDispatcher is not nullable, but 'null' contains null (see https://psalm.dev/144) Error: The declared return type 'string' for Symfony\Component\Form\ButtonBuilder::getAction is not nullable, but 'null' contains null (see https://psalm.dev/144) Error: The declared return type 'string' for Symfony\Component\Form\ButtonBuilder::getMethod is not nullable, but 'null' contains null (see https://psalm.dev/144) Error: The declared return type 'Symfony\Component\Form\RequestHandlerInterface' for Symfony\Component\Form\ButtonBuilder::getRequestHandler is not nullable, but 'null' contains null (see https://psalm.dev/144) Error: The declared return type 'Symfony\Component\Form\FormFactoryInterface' for Symfony\Component\Form\FormConfigBuilder::getFormFactory is not nullable, but 'Symfony\Component\Form\FormFactoryInterface|null' contains null (see https://psalm.dev/144) Error: The declared return type 'string' for Symfony\Component\Form\FormConfigBuilder::getAction is not nullable, but 'null|string' contains null (see https://psalm.dev/144) Commits ------- ea606ea [Form] Fix return types in form builder
2 parents d1a2d21 + ea606ea commit b1115f9

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,12 @@ public function setIsEmptyCallback(?callable $isEmptyCallback)
430430

431431
/**
432432
* Unsupported method.
433+
*
434+
* @throws BadMethodCallException
433435
*/
434436
public function getEventDispatcher()
435437
{
436-
return null;
438+
throw new BadMethodCallException('Buttons do not support event dispatching.');
437439
}
438440

439441
/**
@@ -626,26 +628,32 @@ public function getFormFactory()
626628

627629
/**
628630
* Unsupported method.
631+
*
632+
* @throws BadMethodCallException
629633
*/
630634
public function getAction()
631635
{
632-
return null;
636+
throw new BadMethodCallException('Buttons do not support actions.');
633637
}
634638

635639
/**
636640
* Unsupported method.
641+
*
642+
* @throws BadMethodCallException
637643
*/
638644
public function getMethod()
639645
{
640-
return null;
646+
throw new BadMethodCallException('Buttons do not support methods.');
641647
}
642648

643649
/**
644650
* Unsupported method.
651+
*
652+
* @throws BadMethodCallException
645653
*/
646654
public function getRequestHandler()
647655
{
648-
return null;
656+
throw new BadMethodCallException('Buttons do not support request handlers.');
649657
}
650658

651659
/**

src/Symfony/Component/Form/FormConfigBuilder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
8888
*/
8989
private $formFactory;
9090

91-
/**
92-
* @var string|null
93-
*/
94-
private $action;
95-
91+
private $action = '';
9692
private $method = 'POST';
9793

9894
/**
@@ -396,6 +392,10 @@ public function getDataLocked()
396392
*/
397393
public function getFormFactory()
398394
{
395+
if (!isset($this->formFactory)) {
396+
throw new BadMethodCallException('The form factory must be set before retrieving it.');
397+
}
398+
399399
return $this->formFactory;
400400
}
401401

0 commit comments

Comments
 (0)