minor #41869 [Form] better form doc types to support static analysis (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] better form doc types to support static analysis

| Q             | A
| ------------- | ---
| Branch?       | 4.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       |  <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        |

otherwise phpstan will complain in custom FormTypes like

```
class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
`````

that it does not know what the iterable $builder and $options are about.

Commits
-------

56900d2b24 [Form] better form doc types to support static analysis
This commit is contained in:
Fabien Potencier 2021-07-02 12:25:11 +02:00
commit 92013312f3
3 changed files with 14 additions and 4 deletions

View File

@ -13,6 +13,8 @@ namespace Symfony\Component\Form;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @extends \Traversable<string, self>
*/
interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuilderInterface
{
@ -25,6 +27,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
*
* @param string|FormBuilderInterface $child
* @param string|null $type
* @param array<string, mixed> $options
*
* @return self
*/
@ -33,8 +36,9 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
/**
* Creates a form builder.
*
* @param string $name The name of the form or the name of the property
* @param string|null $type The type of the form or null if name is a property
* @param string $name The name of the form or the name of the property
* @param string|null $type The type of the form or null if name is a property
* @param array<string, mixed> $options
*
* @return self
*/
@ -72,7 +76,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
/**
* Returns the children.
*
* @return array
* @return array<string, self>
*/
public function all();

View File

@ -229,7 +229,7 @@ interface FormConfigInterface
/**
* Returns all options passed during the construction of the form.
*
* @return array The passed options
* @return array<string, mixed> The passed options
*/
public function getOptions();

View File

@ -24,6 +24,8 @@ interface FormTypeInterface
* This method is called for each type in the hierarchy starting from the
* top most type. Type extensions can further modify the form.
*
* @param array<string, mixed> $options
*
* @see FormTypeExtensionInterface::buildForm()
*/
public function buildForm(FormBuilderInterface $builder, array $options);
@ -38,6 +40,8 @@ interface FormTypeInterface
* This means that you cannot access child views in this method. If you need
* to do so, move your logic to {@link finishView()} instead.
*
* @param array<string, mixed> $options
*
* @see FormTypeExtensionInterface::buildView()
*/
public function buildView(FormView $view, FormInterface $form, array $options);
@ -53,6 +57,8 @@ interface FormTypeInterface
* such logic in this method that actually accesses child views. For everything
* else you are recommended to implement {@link buildView()} instead.
*
* @param array<string, mixed> $options
*
* @see FormTypeExtensionInterface::finishView()
*/
public function finishView(FormView $view, FormInterface $form, array $options);