[Form] fix some type annotations

This commit is contained in:
Nicolas Grekas 2021-07-07 11:10:12 +02:00
parent ba7e97d528
commit e49441d5c2
7 changed files with 38 additions and 106 deletions

View File

@ -371,8 +371,8 @@ class Button implements \IteratorAggregate, FormInterface
/** /**
* Submits data to the button. * Submits data to the button.
* *
* @param string|null $submittedData Not used * @param array|string|null $submittedData Not used
* @param bool $clearMissing Not used * @param bool $clearMissing Not used
* *
* @return $this * @return $this
* *

View File

@ -101,10 +101,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function get($name) public function get($name)
@ -115,10 +111,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function remove($name) public function remove($name)
@ -129,8 +121,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* @param string $name
*
* @return bool Always returns false * @return bool Always returns false
*/ */
public function has($name) public function has($name)
@ -161,12 +151,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param string $eventName
* @param callable $listener
* @param int $priority
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function addEventListener($eventName, $listener, $priority = 0) public function addEventListener($eventName, $listener, $priority = 0)
@ -177,8 +161,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function addEventSubscriber(EventSubscriberInterface $subscriber) public function addEventSubscriber(EventSubscriberInterface $subscriber)
@ -189,10 +171,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $forcePrepend
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false) public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false)
@ -203,8 +181,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function resetViewTransformers() public function resetViewTransformers()
@ -215,10 +191,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $forceAppend
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false) public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false)
@ -229,8 +201,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function resetModelTransformers() public function resetModelTransformers()
@ -261,8 +231,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setDataMapper(DataMapperInterface $dataMapper = null) public function setDataMapper(DataMapperInterface $dataMapper = null)
@ -287,10 +255,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param mixed $emptyData
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setEmptyData($emptyData) public function setEmptyData($emptyData)
@ -301,10 +265,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $errorBubbling
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setErrorBubbling($errorBubbling) public function setErrorBubbling($errorBubbling)
@ -315,10 +275,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $required
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setRequired($required) public function setRequired($required)
@ -329,10 +285,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param null $propertyPath
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setPropertyPath($propertyPath) public function setPropertyPath($propertyPath)
@ -343,10 +295,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $mapped
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setMapped($mapped) public function setMapped($mapped)
@ -357,10 +305,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $byReference
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setByReference($byReference) public function setByReference($byReference)
@ -371,10 +315,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $compound
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setCompound($compound) public function setCompound($compound)
@ -397,10 +337,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param mixed $data
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setData($data) public function setData($data)
@ -411,10 +347,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @param bool $locked
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setDataLocked($locked) public function setDataLocked($locked)
@ -425,8 +357,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* This method should not be invoked.
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setFormFactory(FormFactoryInterface $formFactory) public function setFormFactory(FormFactoryInterface $formFactory)
@ -437,8 +367,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* @param string $action
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setAction($action) public function setAction($action)
@ -449,8 +377,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* @param string $method
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setMethod($method) public function setMethod($method)
@ -471,8 +397,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* @param bool $initialize
*
* @return $this * @return $this
* *
* @throws BadMethodCallException * @throws BadMethodCallException
@ -489,8 +413,6 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/** /**
* Unsupported method. * Unsupported method.
* *
* @param bool $inheritData
*
* @throws BadMethodCallException * @throws BadMethodCallException
*/ */
public function setInheritData($inheritData) public function setInheritData($inheritData)

View File

@ -18,6 +18,7 @@ use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
/** /**
* Adds property path support to a choice list factory. * Adds property path support to a choice list factory.
@ -59,11 +60,9 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @param iterable $choices The choices * @param mixed $value
* @param callable|string|PropertyPath|null $value The callable or path for
* generating the choice values
* *
* @return ChoiceListInterface The choice list * @return ChoiceListInterface
*/ */
public function createListFromChoices($choices, $value = null) public function createListFromChoices($choices, $value = null)
{ {
@ -71,7 +70,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$value = new PropertyPath($value); $value = new PropertyPath($value);
} }
if ($value instanceof PropertyPath) { if ($value instanceof PropertyPathInterface) {
$accessor = $this->propertyAccessor; $accessor = $this->propertyAccessor;
$value = function ($choice) use ($accessor, $value) { $value = function ($choice) use ($accessor, $value) {
// The callable may be invoked with a non-object/array value // The callable may be invoked with a non-object/array value
@ -88,10 +87,9 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @param callable|string|PropertyPath|null $value The callable or path for * @param mixed $value
* generating the choice values
* *
* @return ChoiceListInterface The choice list * @return ChoiceListInterface
*/ */
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null) public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
{ {
@ -99,7 +97,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$value = new PropertyPath($value); $value = new PropertyPath($value);
} }
if ($value instanceof PropertyPath) { if ($value instanceof PropertyPathInterface) {
$accessor = $this->propertyAccessor; $accessor = $this->propertyAccessor;
$value = function ($choice) use ($accessor, $value) { $value = function ($choice) use ($accessor, $value) {
// The callable may be invoked with a non-object/array value // The callable may be invoked with a non-object/array value
@ -116,13 +114,13 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @param array|callable|string|PropertyPath|null $preferredChoices The preferred choices * @param mixed $preferredChoices
* @param callable|string|PropertyPath|null $label The callable or path generating the choice labels * @param mixed $label
* @param callable|string|PropertyPath|null $index The callable or path generating the view indices * @param mixed $index
* @param callable|string|PropertyPath|null $groupBy The callable or path generating the group names * @param mixed $groupBy
* @param array|callable|string|PropertyPath|null $attr The callable or path generating the HTML attributes * @param mixed $attr
* *
* @return ChoiceListView The choice list view * @return ChoiceListView
*/ */
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null) public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
{ {
@ -132,7 +130,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$label = new PropertyPath($label); $label = new PropertyPath($label);
} }
if ($label instanceof PropertyPath) { if ($label instanceof PropertyPathInterface) {
$label = function ($choice) use ($accessor, $label) { $label = function ($choice) use ($accessor, $label) {
return $accessor->getValue($choice, $label); return $accessor->getValue($choice, $label);
}; };
@ -142,7 +140,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$preferredChoices = new PropertyPath($preferredChoices); $preferredChoices = new PropertyPath($preferredChoices);
} }
if ($preferredChoices instanceof PropertyPath) { if ($preferredChoices instanceof PropertyPathInterface) {
$preferredChoices = function ($choice) use ($accessor, $preferredChoices) { $preferredChoices = function ($choice) use ($accessor, $preferredChoices) {
try { try {
return $accessor->getValue($choice, $preferredChoices); return $accessor->getValue($choice, $preferredChoices);
@ -157,7 +155,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$index = new PropertyPath($index); $index = new PropertyPath($index);
} }
if ($index instanceof PropertyPath) { if ($index instanceof PropertyPathInterface) {
$index = function ($choice) use ($accessor, $index) { $index = function ($choice) use ($accessor, $index) {
return $accessor->getValue($choice, $index); return $accessor->getValue($choice, $index);
}; };
@ -167,7 +165,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$groupBy = new PropertyPath($groupBy); $groupBy = new PropertyPath($groupBy);
} }
if ($groupBy instanceof PropertyPath) { if ($groupBy instanceof PropertyPathInterface) {
$groupBy = function ($choice) use ($accessor, $groupBy) { $groupBy = function ($choice) use ($accessor, $groupBy) {
try { try {
return $accessor->getValue($choice, $groupBy); return $accessor->getValue($choice, $groupBy);
@ -182,7 +180,7 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
$attr = new PropertyPath($attr); $attr = new PropertyPath($attr);
} }
if ($attr instanceof PropertyPath) { if ($attr instanceof PropertyPathInterface) {
$attr = function ($choice) use ($accessor, $attr) { $attr = function ($choice) use ($accessor, $attr) {
return $accessor->getValue($choice, $attr); return $accessor->getValue($choice, $attr);
}; };

View File

@ -260,8 +260,16 @@ class FormValidator extends ConstraintValidator
private static function getConstraintsInGroups($constraints, $group) private static function getConstraintsInGroups($constraints, $group)
{ {
return array_filter($constraints, static function (Constraint $constraint) use ($group) { $groups = (array) $group;
return \in_array($group, $constraint->groups, true);
return array_filter($constraints, static function (Constraint $constraint) use ($groups) {
foreach ($groups as $group) {
if (\in_array($group, $constraint->groups, true)) {
return true;
}
}
return false;
}); });
} }
} }

View File

@ -34,8 +34,8 @@ class SubmitButton extends Button implements ClickableInterface
/** /**
* Submits data to the button. * Submits data to the button.
* *
* @param string|null $submittedData The data * @param array|string|null $submittedData The data
* @param bool $clearMissing Not used * @param bool $clearMissing Not used
* *
* @return $this * @return $this
* *

View File

@ -67,6 +67,8 @@ class OptionsResolverWrapper extends OptionsResolver
} }
/** /**
* @param string|array $allowedTypes
*
* @return $this * @return $this
*/ */
public function setAllowedTypes($option, $allowedTypes): self public function setAllowedTypes($option, $allowedTypes): self
@ -81,6 +83,8 @@ class OptionsResolverWrapper extends OptionsResolver
} }
/** /**
* @param string|array $allowedTypes
*
* @return $this * @return $this
*/ */
public function addAllowedTypes($option, $allowedTypes): self public function addAllowedTypes($option, $allowedTypes): self

View File

@ -56,7 +56,7 @@ class GroupSequence
/** /**
* The groups in the sequence. * The groups in the sequence.
* *
* @var string[]|string[][]|GroupSequence[] * @var array<string|string[]|GroupSequence>
*/ */
public $groups; public $groups;
@ -79,7 +79,7 @@ class GroupSequence
/** /**
* Creates a new group sequence. * Creates a new group sequence.
* *
* @param string[] $groups The groups in the sequence * @param array<string|string[]|GroupSequence> $groups The groups in the sequence
*/ */
public function __construct(array $groups) public function __construct(array $groups)
{ {