Skip to content

Commit 4f3822e

Browse files
minor symfony#52861 [Form] Adding @var PHPDoc to silence psalm (ThomasLandauer)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Form] Adding ``@var`` PHPDoc to silence psalm | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes (kind of) | New feature? | no | Deprecations? | no | Issues | Fix symfony#52829 | License | MIT The goal is to add some PHPDoc to silence the psalm warnings mentioned in the linked issue, without changing the actual type hint (would be a BC break). I found three ways to achieve this: * Adding ``@var`` to the variable *in the next line*. That's what I'm doing in this PR. The idea is taken from https://stackoverflow.com/a/46842721/1668200 . It looks weird, but it's only a small change... * Adding ``@param`` above the anonymous function. Would require to move it to a new line and subsequently indent the following ~50 lines: ```php $builder->addEventListener(FormEvents::PRE_SUBMIT, /** `@param` PreSubmitEvent $event */ static function (FormEvent $event) use ($choiceList, $options, &$unknownValues) { // ... } ); ``` * Refactoring by extracting the anonymous callback function to a dedicated method. Waiting for feedback here, then I'll do the same in [`TimeType`](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php#L64) and [`FileType`](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Form/Extension/Core/Type/FileType.php#L50) Commits ------- d364472 [Form] Adding ``@var`` PHPDoc to silence psalm
2 parents 9222754 + d364472 commit 4f3822e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
3131
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
3232
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
33+
use Symfony\Component\Form\Event\PreSubmitEvent;
3334
use Symfony\Component\Form\Exception\TransformationFailedException;
3435
use Symfony\Component\Form\Extension\Core\DataMapper\CheckboxListMapper;
3536
use Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper;
@@ -101,6 +102,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
101102
// Make sure that scalar, submitted values are converted to arrays
102103
// which can be submitted to the checkboxes/radio buttons
103104
$builder->addEventListener(FormEvents::PRE_SUBMIT, static function (FormEvent $event) use ($choiceList, $options, &$unknownValues) {
105+
/** @var PreSubmitEvent $event */
104106
$form = $event->getForm();
105107
$data = $event->getData();
106108

0 commit comments

Comments
 (0)