From 0480be6a4b4126d3ef5c2c46e3272afea317b0ae Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 6 Jul 2021 10:45:38 +0200 Subject: [PATCH] [Form] add union types --- .../Component/Form/AbstractRendererEngine.php | 2 +- src/Symfony/Component/Form/Button.php | 32 +++------ src/Symfony/Component/Form/ButtonBuilder.php | 25 +++---- .../Component/Form/CallbackTransformer.php | 4 +- .../Component/Form/ChoiceList/ChoiceList.php | 70 ++++++++----------- .../Factory/Cache/AbstractStaticOption.php | 11 +-- .../Factory/CachingFactoryDecorator.php | 34 +++++---- .../Factory/ChoiceListFactoryInterface.php | 2 +- .../Factory/DefaultChoiceListFactory.php | 4 +- .../Factory/PropertyAccessDecorator.php | 6 +- .../Form/ChoiceList/View/ChoiceView.php | 2 +- .../Form/Console/Descriptor/Descriptor.php | 2 +- .../Component/Form/DataAccessorInterface.php | 21 ++---- .../Component/Form/DataMapperInterface.php | 4 +- .../Form/DataTransformerInterface.php | 4 +- .../Exception/UnexpectedTypeException.php | 2 +- .../Core/DataAccessor/CallbackAccessor.php | 8 +-- .../Core/DataAccessor/ChainAccessor.php | 8 +-- .../DataAccessor/PropertyPathAccessor.php | 17 ++--- .../Core/DataMapper/CheckboxListMapper.php | 2 +- .../Extension/Core/DataMapper/DataMapper.php | 2 +- .../Core/DataMapper/RadioListMapper.php | 2 +- .../ArrayToPartsTransformer.php | 4 +- .../BooleanToStringTransformer.php | 4 +- .../ChoiceToValueTransformer.php | 4 +- .../ChoicesToValuesTransformer.php | 4 +- .../DataTransformer/DataTransformerChain.php | 4 +- .../DateIntervalToArrayTransformer.php | 4 +- .../DateIntervalToStringTransformer.php | 4 +- ...DateTimeImmutableToDateTimeTransformer.php | 4 +- .../DateTimeToArrayTransformer.php | 4 +- ...ateTimeToHtml5LocalDateTimeTransformer.php | 4 +- .../DateTimeToLocalizedStringTransformer.php | 4 +- .../DateTimeToRfc3339Transformer.php | 4 +- .../DateTimeToStringTransformer.php | 4 +- .../DateTimeToTimestampTransformer.php | 4 +- .../DateTimeZoneToStringTransformer.php | 4 +- .../IntegerToLocalizedStringTransformer.php | 4 +- .../IntlTimeZoneToStringTransformer.php | 4 +- .../MoneyToLocalizedStringTransformer.php | 4 +- .../NumberToLocalizedStringTransformer.php | 12 ++-- .../PercentToLocalizedStringTransformer.php | 4 +- .../StringToFloatTransformer.php | 4 +- .../UlidToStringTransformer.php | 4 +- .../UuidToStringTransformer.php | 4 +- .../ValueToDuplicatesTransformer.php | 8 +-- .../WeekToArrayTransformer.php | 4 +- .../Core/EventListener/ResizeFormListener.php | 7 +- .../Form/Extension/Core/Type/FileType.php | 4 +- .../Form/Extension/Core/Type/TextType.php | 4 +- .../HttpFoundationRequestHandler.php | 6 +- .../Validator/Constraints/FormValidator.php | 18 +++-- .../Validator/ValidatorTypeGuesser.php | 2 +- src/Symfony/Component/Form/Form.php | 24 +++---- src/Symfony/Component/Form/FormBuilder.php | 10 +-- .../Component/Form/FormBuilderInterface.php | 5 +- .../Component/Form/FormConfigBuilder.php | 12 ++-- .../Form/FormConfigBuilderInterface.php | 8 +-- .../Component/Form/FormConfigInterface.php | 8 +-- src/Symfony/Component/Form/FormError.php | 2 +- .../Component/Form/FormErrorIterator.php | 14 ++-- src/Symfony/Component/Form/FormEvent.php | 9 +-- src/Symfony/Component/Form/FormFactory.php | 14 ++-- .../Component/Form/FormFactoryInterface.php | 14 ++-- src/Symfony/Component/Form/FormInterface.php | 10 ++- src/Symfony/Component/Form/FormRenderer.php | 2 +- .../Form/FormRendererEngineInterface.php | 4 +- .../Component/Form/FormRendererInterface.php | 2 +- src/Symfony/Component/Form/FormView.php | 8 +-- .../Component/Form/Guess/ValueGuess.php | 6 +- .../Component/Form/NativeRequestHandler.php | 10 +-- .../Form/RequestHandlerInterface.php | 8 +-- .../Component/Form/ReversedTransformer.php | 4 +- src/Symfony/Component/Form/SubmitButton.php | 5 +- .../Component/Form/Tests/FormBuilderTest.php | 6 -- .../Component/Form/Tests/VersionAwareTest.php | 5 +- src/Symfony/Component/Form/Util/FormUtil.php | 4 +- .../Form/Util/OptionsResolverWrapper.php | 8 ++- .../Component/Form/Util/OrderedHashMap.php | 8 +-- .../Validator/Constraints/GroupSequence.php | 4 +- 80 files changed, 271 insertions(+), 360 deletions(-) diff --git a/src/Symfony/Component/Form/AbstractRendererEngine.php b/src/Symfony/Component/Form/AbstractRendererEngine.php index 905c98bbeb3d7..4179e392d7738 100644 --- a/src/Symfony/Component/Form/AbstractRendererEngine.php +++ b/src/Symfony/Component/Form/AbstractRendererEngine.php @@ -44,7 +44,7 @@ public function __construct(array $defaultThemes = []) /** * {@inheritdoc} */ - public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true) + public function setTheme(FormView $view, mixed $themes, bool $useDefaultThemes = true) { $cacheKey = $view->vars[self::CACHE_KEY_VAR]; diff --git a/src/Symfony/Component/Form/Button.php b/src/Symfony/Component/Form/Button.php index e8d521047f6e2..2761db7e329bd 100644 --- a/src/Symfony/Component/Form/Button.php +++ b/src/Symfony/Component/Form/Button.php @@ -47,11 +47,9 @@ public function __construct(FormConfigInterface $config) /** * Unsupported method. * - * @param mixed $offset - * * @return bool Always returns false */ - public function offsetExists($offset) + public function offsetExists(mixed $offset) { return false; } @@ -61,11 +59,9 @@ public function offsetExists($offset) * * This method should not be invoked. * - * @param mixed $offset - * * @throws BadMethodCallException */ - public function offsetGet($offset) + public function offsetGet(mixed $offset) { throw new BadMethodCallException('Buttons cannot have children.'); } @@ -75,12 +71,9 @@ public function offsetGet($offset) * * This method should not be invoked. * - * @param mixed $offset - * @param mixed $value - * * @throws BadMethodCallException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value) { throw new BadMethodCallException('Buttons cannot have children.'); } @@ -90,11 +83,9 @@ public function offsetSet($offset, $value) * * This method should not be invoked. * - * @param mixed $offset - * * @throws BadMethodCallException */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset) { throw new BadMethodCallException('Buttons cannot have children.'); } @@ -128,7 +119,7 @@ public function getParent() * * @throws BadMethodCallException */ - public function add($child, string $type = null, array $options = []) + public function add(string|FormInterface $child, string $type = null, array $options = []) { throw new BadMethodCallException('Buttons cannot have children.'); } @@ -188,11 +179,9 @@ public function getErrors(bool $deep = false, bool $flatten = true) * * This method should not be invoked. * - * @param mixed $modelData - * * @return $this */ - public function setData($modelData) + public function setData(mixed $modelData) { // no-op, called during initialization of the form tree return $this; @@ -353,11 +342,9 @@ public function initialize() /** * Unsupported method. * - * @param mixed $request - * * @throws BadMethodCallException */ - public function handleRequest($request = null) + public function handleRequest(mixed $request = null) { throw new BadMethodCallException('Buttons cannot handle requests. Call handleRequest() on the root form instead.'); } @@ -365,14 +352,11 @@ public function handleRequest($request = null) /** * Submits data to the button. * - * @param string|null $submittedData Not used - * @param bool $clearMissing Not used - * * @return $this * * @throws Exception\AlreadySubmittedException if the button has already been submitted */ - public function submit($submittedData, bool $clearMissing = true) + public function submit(array|string|null $submittedData, bool $clearMissing = true) { if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once.'); diff --git a/src/Symfony/Component/Form/ButtonBuilder.php b/src/Symfony/Component/Form/ButtonBuilder.php index bf020baf53787..8c5a8b9a6d7f0 100644 --- a/src/Symfony/Component/Form/ButtonBuilder.php +++ b/src/Symfony/Component/Form/ButtonBuilder.php @@ -14,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\Exception\BadMethodCallException; use Symfony\Component\Form\Exception\InvalidArgumentException; +use Symfony\Component\PropertyAccess\PropertyPathInterface; /** * A builder for {@link Button} instances. @@ -71,7 +72,7 @@ public function __construct(?string $name, array $options = []) * * @throws BadMethodCallException */ - public function add($child, string $type = null, array $options = []) + public function add(string|FormBuilderInterface $child, string $type = null, array $options = []) { throw new BadMethodCallException('Buttons cannot have children.'); } @@ -217,7 +218,7 @@ public function resetModelTransformers() /** * {@inheritdoc} */ - public function setAttribute(string $name, $value) + public function setAttribute(string $name, mixed $value) { $this->attributes[$name] = $value; @@ -263,11 +264,9 @@ public function setDisabled(bool $disabled) * * This method should not be invoked. * - * @param mixed $emptyData - * * @throws BadMethodCallException */ - public function setEmptyData($emptyData) + public function setEmptyData(mixed $emptyData) { throw new BadMethodCallException('Buttons do not support empty data.'); } @@ -301,11 +300,9 @@ public function setRequired(bool $required) * * This method should not be invoked. * - * @param null $propertyPath - * * @throws BadMethodCallException */ - public function setPropertyPath($propertyPath) + public function setPropertyPath(string|PropertyPathInterface|null $propertyPath) { throw new BadMethodCallException('Buttons do not support property paths.'); } @@ -363,11 +360,9 @@ public function setType(ResolvedFormTypeInterface $type) * * This method should not be invoked. * - * @param mixed $data - * * @throws BadMethodCallException */ - public function setData($data) + public function setData(mixed $data) { throw new BadMethodCallException('Buttons do not support data.'); } @@ -629,11 +624,9 @@ public function hasAttribute(string $name) /** * Returns the value of the given attribute. * - * @param mixed $default The value returned if the attribute does not exist - * * @return mixed The attribute value */ - public function getAttribute(string $name, $default = null) + public function getAttribute(string $name, mixed $default = null) { return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default; } @@ -739,11 +732,9 @@ public function hasOption(string $name) /** * Returns the value of a specific option. * - * @param mixed $default The value returned if the option does not exist - * * @return mixed The option value */ - public function getOption(string $name, $default = null) + public function getOption(string $name, mixed $default = null) { return \array_key_exists($name, $this->options) ? $this->options[$name] : $default; } diff --git a/src/Symfony/Component/Form/CallbackTransformer.php b/src/Symfony/Component/Form/CallbackTransformer.php index 5125214ff959c..0f7422ae64496 100644 --- a/src/Symfony/Component/Form/CallbackTransformer.php +++ b/src/Symfony/Component/Form/CallbackTransformer.php @@ -29,7 +29,7 @@ public function __construct(callable $transform, callable $reverseTransform) /** * {@inheritdoc} */ - public function transform($data) + public function transform(mixed $data) { return ($this->transform)($data); } @@ -37,7 +37,7 @@ public function transform($data) /** * {@inheritdoc} */ - public function reverseTransform($data) + public function reverseTransform(mixed $data) { return ($this->reverseTransform)($data); } diff --git a/src/Symfony/Component/Form/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ChoiceList.php index df63c83d89dee..31166c1bdfcb7 100644 --- a/src/Symfony/Component/Form/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ChoiceList.php @@ -35,11 +35,10 @@ final class ChoiceList /** * Creates a cacheable loader from any callable providing iterable choices. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable $choices A callable that must return iterable choices or grouped choices - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the loader + * @param callable $choices A callable that must return iterable choices or grouped choices + * @param mixed $vary Dynamic data used to compute a unique hash when caching the loader */ - public static function lazy($formType, callable $choices, $vary = null): ChoiceLoader + public static function lazy(FormTypeInterface|FormTypeExtensionInterface $formType, callable $choices, mixed $vary = null): ChoiceLoader { return self::loader($formType, new CallbackChoiceLoader($choices), $vary); } @@ -47,11 +46,10 @@ public static function lazy($formType, callable $choices, $vary = null): ChoiceL /** * Decorates a loader to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param ChoiceLoaderInterface $loader A loader responsible for creating loading choices or grouped choices - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the loader + * @param ChoiceLoaderInterface $loader A loader responsible for creating loading choices or grouped choices + * @param mixed $vary Dynamic data used to compute a unique hash when caching the loader */ - public static function loader($formType, ChoiceLoaderInterface $loader, $vary = null): ChoiceLoader + public static function loader(FormTypeInterface|FormTypeExtensionInterface $formType, ChoiceLoaderInterface $loader, mixed $vary = null): ChoiceLoader { return new ChoiceLoader($formType, $loader, $vary); } @@ -59,21 +57,19 @@ public static function loader($formType, ChoiceLoaderInterface $loader, $vary = /** * Decorates a "choice_value" callback to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable $value Any pseudo callable to create a unique string value from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback + * @param callable|array $value Any pseudo callable to create a unique string value from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the callback */ - public static function value($formType, $value, $vary = null): ChoiceValue + public static function value(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $value, mixed $vary = null): ChoiceValue { return new ChoiceValue($formType, $value, $vary); } /** - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable $filter Any pseudo callable to filter a choice list - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback + * @param callable|array $filter Any pseudo callable to filter a choice list + * @param mixed $vary Dynamic data used to compute a unique hash when caching the callback */ - public static function filter($formType, $filter, $vary = null): ChoiceFilter + public static function filter(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $filter, mixed $vary = null): ChoiceFilter { return new ChoiceFilter($formType, $filter, $vary); } @@ -81,11 +77,10 @@ public static function filter($formType, $filter, $vary = null): ChoiceFilter /** * Decorates a "choice_label" option to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable|false $label Any pseudo callable to create a label from a choice or false to discard it - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option + * @param callable|false $label Any pseudo callable to create a label from a choice or false to discard it + * @param mixed $vary Dynamic data used to compute a unique hash when caching the option */ - public static function label($formType, $label, $vary = null): ChoiceLabel + public static function label(FormTypeInterface|FormTypeExtensionInterface $formType, callable|false $label, mixed $vary = null): ChoiceLabel { return new ChoiceLabel($formType, $label, $vary); } @@ -93,11 +88,10 @@ public static function label($formType, $label, $vary = null): ChoiceLabel /** * Decorates a "choice_name" callback to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable $fieldName Any pseudo callable to create a field name from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback + * @param callable|array $fieldName Any pseudo callable to create a field name from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the callback */ - public static function fieldName($formType, $fieldName, $vary = null): ChoiceFieldName + public static function fieldName(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $fieldName, mixed $vary = null): ChoiceFieldName { return new ChoiceFieldName($formType, $fieldName, $vary); } @@ -105,11 +99,10 @@ public static function fieldName($formType, $fieldName, $vary = null): ChoiceFie /** * Decorates a "choice_attr" option to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable|array $attr Any pseudo callable or array to create html attributes from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option + * @param callable|array $attr Any pseudo callable or array to create html attributes from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the option */ - public static function attr($formType, $attr, $vary = null): ChoiceAttr + public static function attr(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $attr, mixed $vary = null): ChoiceAttr { return new ChoiceAttr($formType, $attr, $vary); } @@ -117,11 +110,10 @@ public static function attr($formType, $attr, $vary = null): ChoiceAttr /** * Decorates a "choice_translation_parameters" option to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable|array $translationParameters Any pseudo callable or array to create translation parameters from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option + * @param callable|array $translationParameters Any pseudo callable or array to create translation parameters from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the option */ - public static function translationParameters($formType, $translationParameters, $vary = null): ChoiceTranslationParameters + public static function translationParameters(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $translationParameters, mixed $vary = null): ChoiceTranslationParameters { return new ChoiceTranslationParameters($formType, $translationParameters, $vary); } @@ -129,11 +121,10 @@ public static function translationParameters($formType, $translationParameters, /** * Decorates a "group_by" callback to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable $groupBy Any pseudo callable to return a group name from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the callback + * @param callable|array $groupBy Any pseudo callable to return a group name from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the callback */ - public static function groupBy($formType, $groupBy, $vary = null): GroupBy + public static function groupBy(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $groupBy, mixed $vary = null): GroupBy { return new GroupBy($formType, $groupBy, $vary); } @@ -141,11 +132,10 @@ public static function groupBy($formType, $groupBy, $vary = null): GroupBy /** * Decorates a "preferred_choices" option to make it cacheable. * - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param callable|array $preferred Any pseudo callable or array to return a group name from a choice - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option + * @param callable|array $preferred Any pseudo callable or array to return a group name from a choice + * @param mixed $vary Dynamic data used to compute a unique hash when caching the option */ - public static function preferred($formType, $preferred, $vary = null): PreferredChoice + public static function preferred(FormTypeInterface|FormTypeExtensionInterface $formType, callable|array $preferred, mixed $vary = null): PreferredChoice { return new PreferredChoice($formType, $preferred, $vary); } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php b/src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php index 42b31e0275019..e209cf15658b2 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/Cache/AbstractStaticOption.php @@ -34,16 +34,11 @@ abstract class AbstractStaticOption private $option; /** - * @param FormTypeInterface|FormTypeExtensionInterface $formType A form type or type extension configuring a cacheable choice list - * @param mixed $option Any pseudo callable, array, string or bool to define a choice list option - * @param mixed|null $vary Dynamic data used to compute a unique hash when caching the option + * @param mixed $option Any pseudo callable, array, string or bool to define a choice list option + * @param mixed $vary Dynamic data used to compute a unique hash when caching the option */ - final public function __construct($formType, $option, $vary = null) + final public function __construct(FormTypeInterface|FormTypeExtensionInterface $formType, mixed $option, mixed $vary = null) { - if (!$formType instanceof FormTypeInterface && !$formType instanceof FormTypeExtensionInterface) { - throw new \TypeError(sprintf('Expected an instance of "%s" or "%s", but got "%s".', FormTypeInterface::class, FormTypeExtensionInterface::class, get_debug_type($formType))); - } - $hash = CachingFactoryDecorator::generateHash([static::class, $formType, $vary]); $this->option = self::$options[$hash] ?? self::$options[$hash] = $option; diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php index 746a1ad064f0a..268f35ce111e0 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php @@ -45,13 +45,11 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface, ResetInterf * Optionally, a namespace string can be passed. Calling this method will * the same values, but different namespaces, will return different hashes. * - * @param mixed $value The value to hash - * * @return string The SHA-256 hash * * @internal */ - public static function generateHash($value, string $namespace = ''): string + public static function generateHash(mixed $value, string $namespace = ''): string { if (\is_object($value)) { $value = spl_object_hash($value); @@ -84,12 +82,12 @@ public function getDecoratedFactory() /** * {@inheritdoc} * - * @param callable|Cache\ChoiceValue|null $value The callable or static option for - * generating the choice values - * @param callable|Cache\ChoiceFilter|null $filter The callable or static option for - * filtering the choices + * @param callable|string|Cache\ChoiceValue|null $value The callable or static option for + * generating the choice values + * @param callable|string|Cache\ChoiceFilter|null $filter The callable or static option for + * filtering the choices */ - public function createListFromChoices(iterable $choices, $value = null, $filter = null) + public function createListFromChoices(iterable $choices, callable|string|Cache\ChoiceValue $value = null, callable|string|Cache\ChoiceFilter $filter = null) { if ($choices instanceof \Traversable) { $choices = iterator_to_array($choices); @@ -127,12 +125,12 @@ public function createListFromChoices(iterable $choices, $value = null, $filter * * @param ChoiceLoaderInterface|Cache\ChoiceLoader $loader The loader or static loader to load * the choices lazily - * @param callable|Cache\ChoiceValue|null $value The callable or static option for + * @param callable|string|Cache\ChoiceValue|null $value The callable or static option for * generating the choice values - * @param callable|Cache\ChoiceFilter|null $filter The callable or static option for + * @param callable|string|Cache\ChoiceFilter|null $filter The callable or static option for * filtering the choices */ - public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null, $filter = null) + public function createListFromLoader(ChoiceLoaderInterface|Cache\ChoiceLoader $loader, callable|string|Cache\ChoiceValue $value = null, callable|string|Cache\ChoiceFilter $filter = null) { $cache = true; @@ -170,14 +168,14 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul /** * {@inheritdoc} * - * @param array|callable|Cache\PreferredChoice|null $preferredChoices The preferred choices - * @param callable|false|Cache\ChoiceLabel|null $label The option or static option generating the choice labels - * @param callable|Cache\ChoiceFieldName|null $index The option or static option generating the view indices - * @param callable|Cache\GroupBy|null $groupBy The option or static option generating the group names - * @param array|callable|Cache\ChoiceAttr|null $attr The option or static option generating the HTML attributes - * @param array|callable|Cache\ChoiceTranslationParameters $labelTranslationParameters The parameters used to translate the choice labels + * @param array|callable|string|Cache\PreferredChoice|null $preferredChoices The preferred choices + * @param callable|false|string|Cache\ChoiceLabel|null $label The option or static option generating the choice labels + * @param callable|string|Cache\ChoiceFieldName|null $index The option or static option generating the view indices + * @param callable|string|Cache\GroupBy|null $groupBy The option or static option generating the group names + * @param array|callable|string|Cache\ChoiceAttr|null $attr The option or static option generating the HTML attributes + * @param array|callable|string|Cache\ChoiceTranslationParameters $labelTranslationParameters The parameters used to translate the choice labels */ - public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelTranslationParameters = []) + public function createView(ChoiceListInterface $list, array|callable|string|Cache\PreferredChoice $preferredChoices = null, callable|false|string|Cache\ChoiceLabel $label = null, callable|string|Cache\ChoiceFieldName $index = null, callable|string|Cache\GroupBy $groupBy = null, array|callable|string|Cache\ChoiceAttr $attr = null, array|callable|string|Cache\ChoiceTranslationParameters $labelTranslationParameters = []) { $cache = true; diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php b/src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php index 311d552616e27..91aad198651d6 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php @@ -84,5 +84,5 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, callable $va * * @return ChoiceListView The choice list view */ - public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, callable $index = null, callable $groupBy = null, $attr = null, $labelTranslationParameters = []); + public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []); } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index 8d5e650c5921e..13c7a96dc0857 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -61,10 +61,8 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, callable $va /** * {@inheritdoc} - * - * @param array|callable $labelTranslationParameters The parameters used to translate the choice labels */ - public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, callable $index = null, callable $groupBy = null, $attr = null, $labelTranslationParameters = []) + public function createView(ChoiceListInterface $list, array|callable $preferredChoices = null, callable|false $label = null, callable $index = null, callable $groupBy = null, array|callable $attr = null, array|callable $labelTranslationParameters = []) { $preferredViews = []; $preferredViewsOrder = []; diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php index 492074286fa25..50ab6972c075a 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php @@ -66,7 +66,7 @@ public function getDecoratedFactory() * * @return ChoiceListInterface The choice list */ - public function createListFromChoices(iterable $choices, $value = null, $filter = null) + public function createListFromChoices(iterable $choices, callable|string|PropertyPath $value = null, callable|string|PropertyPath $filter = null) { if (\is_string($value)) { $value = new PropertyPath($value); @@ -107,7 +107,7 @@ public function createListFromChoices(iterable $choices, $value = null, $filter * * @return ChoiceListInterface The choice list */ - public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null, $filter = null) + public function createListFromLoader(ChoiceLoaderInterface $loader, callable|string|PropertyPath $value = null, callable|string|PropertyPath $filter = null) { if (\is_string($value)) { $value = new PropertyPath($value); @@ -150,7 +150,7 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul * * @return ChoiceListView The choice list view */ - public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null, $labelTranslationParameters = []) + public function createView(ChoiceListInterface $list, array|callable|string|PropertyPath $preferredChoices = null, callable|false|string|PropertyPath $label = null, callable|string|PropertyPath $index = null, callable|string|PropertyPath $groupBy = null, array|callable|string|PropertyPath $attr = null, array|callable|string|PropertyPath $labelTranslationParameters = []) { $accessor = $this->propertyAccessor; diff --git a/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php b/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php index e1d8ac92d8d9d..a98dd79541944 100644 --- a/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php +++ b/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php @@ -43,7 +43,7 @@ class ChoiceView * @param array $attr Additional attributes for the HTML tag * @param array $labelTranslationParameters Additional parameters used to translate the label */ - public function __construct($data, string $value, $label, array $attr = [], array $labelTranslationParameters = []) + public function __construct(mixed $data, string $value, string|TranslatableMessage|false $label, array $attr = [], array $labelTranslationParameters = []) { $this->data = $data; $this->value = $value; diff --git a/src/Symfony/Component/Form/Console/Descriptor/Descriptor.php b/src/Symfony/Component/Form/Console/Descriptor/Descriptor.php index 4aceafbe6952c..50a9351fbe1f1 100644 --- a/src/Symfony/Component/Form/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Component/Form/Console/Descriptor/Descriptor.php @@ -43,7 +43,7 @@ abstract class Descriptor implements DescriptorInterface /** * {@inheritdoc} */ - public function describe(OutputInterface $output, $object, array $options = []) + public function describe(OutputInterface $output, ?object $object, array $options = []) { $this->output = $output instanceof OutputStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output); diff --git a/src/Symfony/Component/Form/DataAccessorInterface.php b/src/Symfony/Component/Form/DataAccessorInterface.php index d128dde074f86..9a27cfc39a20c 100644 --- a/src/Symfony/Component/Form/DataAccessorInterface.php +++ b/src/Symfony/Component/Form/DataAccessorInterface.php @@ -21,25 +21,18 @@ interface DataAccessorInterface /** * Returns the value at the end of the property of the object graph. * - * @param object|array $viewData The view data of the compound form - * @param FormInterface $form The {@link FormInterface()} instance to check - * * @return mixed The value at the end of the property * * @throws Exception\AccessException If unable to read from the given form data */ - public function getValue($viewData, FormInterface $form); + public function getValue(object|array $viewData, FormInterface $form); /** * Sets the value at the end of the property of the object graph. * - * @param object|array $viewData The view data of the compound form - * @param mixed $value The value to set at the end of the object graph - * @param FormInterface $form The {@link FormInterface()} instance to check - * * @throws Exception\AccessException If unable to write the given value */ - public function setValue(&$viewData, $value, FormInterface $form): void; + public function setValue(object|array &$viewData, mixed $value, FormInterface $form): void; /** * Returns whether a value can be read from an object graph. @@ -47,12 +40,9 @@ public function setValue(&$viewData, $value, FormInterface $form): void; * Whenever this method returns true, {@link getValue()} is guaranteed not * to throw an exception when called with the same arguments. * - * @param object|array $viewData The view data of the compound form - * @param FormInterface $form The {@link FormInterface()} instance to check - * * @return bool Whether the value can be read */ - public function isReadable($viewData, FormInterface $form): bool; + public function isReadable(object|array $viewData, FormInterface $form): bool; /** * Returns whether a value can be written at a given object graph. @@ -60,10 +50,7 @@ public function isReadable($viewData, FormInterface $form): bool; * Whenever this method returns true, {@link setValue()} is guaranteed not * to throw an exception when called with the same arguments. * - * @param object|array $viewData The view data of the compound form - * @param FormInterface $form The {@link FormInterface()} instance to check - * * @return bool Whether the value can be set */ - public function isWritable($viewData, FormInterface $form): bool; + public function isWritable(object|array $viewData, FormInterface $form): bool; } diff --git a/src/Symfony/Component/Form/DataMapperInterface.php b/src/Symfony/Component/Form/DataMapperInterface.php index c2cd3601e4b5b..b668de3f35ebb 100644 --- a/src/Symfony/Component/Form/DataMapperInterface.php +++ b/src/Symfony/Component/Form/DataMapperInterface.php @@ -27,7 +27,7 @@ interface DataMapperInterface * * @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported */ - public function mapDataToForms($viewData, \Traversable $forms); + public function mapDataToForms(mixed $viewData, \Traversable $forms); /** * Maps the model data of a list of children forms into the view data of their parent. @@ -58,5 +58,5 @@ public function mapDataToForms($viewData, \Traversable $forms); * * @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported */ - public function mapFormsToData(\Traversable $forms, &$viewData); + public function mapFormsToData(\Traversable $forms, mixed &$viewData); } diff --git a/src/Symfony/Component/Form/DataTransformerInterface.php b/src/Symfony/Component/Form/DataTransformerInterface.php index e5ac5992944e5..7dd07db70a0e7 100644 --- a/src/Symfony/Component/Form/DataTransformerInterface.php +++ b/src/Symfony/Component/Form/DataTransformerInterface.php @@ -59,7 +59,7 @@ interface DataTransformerInterface * * @throws TransformationFailedException when the transformation fails */ - public function transform($value); + public function transform(mixed $value); /** * Transforms a value from the transformed representation to its original @@ -88,5 +88,5 @@ public function transform($value); * * @throws TransformationFailedException when the transformation fails */ - public function reverseTransform($value); + public function reverseTransform(mixed $value); } diff --git a/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php b/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php index d25d4705fa87a..7a4dc295c6d64 100644 --- a/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php +++ b/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php @@ -13,7 +13,7 @@ class UnexpectedTypeException extends InvalidArgumentException { - public function __construct($value, string $expectedType) + public function __construct(mixed $value, string $expectedType) { parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, get_debug_type($value))); } diff --git a/src/Symfony/Component/Form/Extension/Core/DataAccessor/CallbackAccessor.php b/src/Symfony/Component/Form/Extension/Core/DataAccessor/CallbackAccessor.php index fb121450a47dd..5dccf0a0fe7a3 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataAccessor/CallbackAccessor.php +++ b/src/Symfony/Component/Form/Extension/Core/DataAccessor/CallbackAccessor.php @@ -25,7 +25,7 @@ class CallbackAccessor implements DataAccessorInterface /** * {@inheritdoc} */ - public function getValue($data, FormInterface $form) + public function getValue(object|array $data, FormInterface $form) { if (null === $getter = $form->getConfig()->getOption('getter')) { throw new AccessException('Unable to read from the given form data as no getter is defined.'); @@ -37,7 +37,7 @@ public function getValue($data, FormInterface $form) /** * {@inheritdoc} */ - public function setValue(&$data, $value, FormInterface $form): void + public function setValue(object|array &$data, mixed $value, FormInterface $form): void { if (null === $setter = $form->getConfig()->getOption('setter')) { throw new AccessException('Unable to write the given value as no setter is defined.'); @@ -49,7 +49,7 @@ public function setValue(&$data, $value, FormInterface $form): void /** * {@inheritdoc} */ - public function isReadable($data, FormInterface $form): bool + public function isReadable(object|array $data, FormInterface $form): bool { return null !== $form->getConfig()->getOption('getter'); } @@ -57,7 +57,7 @@ public function isReadable($data, FormInterface $form): bool /** * {@inheritdoc} */ - public function isWritable($data, FormInterface $form): bool + public function isWritable(object|array $data, FormInterface $form): bool { return null !== $form->getConfig()->getOption('setter'); } diff --git a/src/Symfony/Component/Form/Extension/Core/DataAccessor/ChainAccessor.php b/src/Symfony/Component/Form/Extension/Core/DataAccessor/ChainAccessor.php index 39e444bb7b0bb..dfd7907c8e44a 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataAccessor/ChainAccessor.php +++ b/src/Symfony/Component/Form/Extension/Core/DataAccessor/ChainAccessor.php @@ -33,7 +33,7 @@ public function __construct(iterable $accessors) /** * {@inheritdoc} */ - public function getValue($data, FormInterface $form) + public function getValue(object|array $data, FormInterface $form) { foreach ($this->accessors as $accessor) { if ($accessor->isReadable($data, $form)) { @@ -47,7 +47,7 @@ public function getValue($data, FormInterface $form) /** * {@inheritdoc} */ - public function setValue(&$data, $value, FormInterface $form): void + public function setValue(object|array &$data, mixed $value, FormInterface $form): void { foreach ($this->accessors as $accessor) { if ($accessor->isWritable($data, $form)) { @@ -63,7 +63,7 @@ public function setValue(&$data, $value, FormInterface $form): void /** * {@inheritdoc} */ - public function isReadable($data, FormInterface $form): bool + public function isReadable(object|array $data, FormInterface $form): bool { foreach ($this->accessors as $accessor) { if ($accessor->isReadable($data, $form)) { @@ -77,7 +77,7 @@ public function isReadable($data, FormInterface $form): bool /** * {@inheritdoc} */ - public function isWritable($data, FormInterface $form): bool + public function isWritable(object|array $data, FormInterface $form): bool { foreach ($this->accessors as $accessor) { if ($accessor->isWritable($data, $form)) { diff --git a/src/Symfony/Component/Form/Extension/Core/DataAccessor/PropertyPathAccessor.php b/src/Symfony/Component/Form/Extension/Core/DataAccessor/PropertyPathAccessor.php index bd1c382151324..e8ff3e0c081a1 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataAccessor/PropertyPathAccessor.php +++ b/src/Symfony/Component/Form/Extension/Core/DataAccessor/PropertyPathAccessor.php @@ -18,6 +18,7 @@ use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; +use Symfony\Component\PropertyAccess\PropertyPathInterface; /** * Writes and reads values to/from an object or array using property path. @@ -37,7 +38,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null) /** * {@inheritdoc} */ - public function getValue($data, FormInterface $form) + public function getValue(object|array $data, FormInterface $form) { if (null === $propertyPath = $form->getPropertyPath()) { throw new AccessException('Unable to read from the given form data as no property path is defined.'); @@ -49,7 +50,7 @@ public function getValue($data, FormInterface $form) /** * {@inheritdoc} */ - public function setValue(&$data, $propertyValue, FormInterface $form): void + public function setValue(object|array &$data, mixed $value, FormInterface $form): void { if (null === $propertyPath = $form->getPropertyPath()) { throw new AccessException('Unable to write the given value as no property path is defined.'); @@ -57,21 +58,21 @@ public function setValue(&$data, $propertyValue, FormInterface $form): void // If the field is of type DateTimeInterface and the data is the same skip the update to // keep the original object hash - if ($propertyValue instanceof \DateTimeInterface && $propertyValue == $this->getPropertyValue($data, $propertyPath)) { + if ($value instanceof \DateTimeInterface && $value == $this->getPropertyValue($data, $propertyPath)) { return; } // If the data is identical to the value in $data, we are // dealing with a reference - if (!\is_object($data) || !$form->getConfig()->getByReference() || $propertyValue !== $this->getPropertyValue($data, $propertyPath)) { - $this->propertyAccessor->setValue($data, $propertyPath, $propertyValue); + if (!\is_object($data) || !$form->getConfig()->getByReference() || $value !== $this->getPropertyValue($data, $propertyPath)) { + $this->propertyAccessor->setValue($data, $propertyPath, $value); } } /** * {@inheritdoc} */ - public function isReadable($data, FormInterface $form): bool + public function isReadable(object|array $data, FormInterface $form): bool { return null !== $form->getPropertyPath(); } @@ -79,12 +80,12 @@ public function isReadable($data, FormInterface $form): bool /** * {@inheritdoc} */ - public function isWritable($data, FormInterface $form): bool + public function isWritable(object|array $data, FormInterface $form): bool { return null !== $form->getPropertyPath(); } - private function getPropertyValue($data, $propertyPath) + private function getPropertyValue(object|array $data, PropertyPathInterface $propertyPath) { try { return $this->propertyAccessor->getValue($data, $propertyPath); diff --git a/src/Symfony/Component/Form/Extension/Core/DataMapper/CheckboxListMapper.php b/src/Symfony/Component/Form/Extension/Core/DataMapper/CheckboxListMapper.php index a6014d7076fc4..64240151d4530 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataMapper/CheckboxListMapper.php +++ b/src/Symfony/Component/Form/Extension/Core/DataMapper/CheckboxListMapper.php @@ -28,7 +28,7 @@ class CheckboxListMapper implements DataMapperInterface /** * {@inheritdoc} */ - public function mapDataToForms($choices, \Traversable $checkboxes) + public function mapDataToForms(mixed $choices, \Traversable $checkboxes) { if (null === $choices) { $choices = []; diff --git a/src/Symfony/Component/Form/Extension/Core/DataMapper/DataMapper.php b/src/Symfony/Component/Form/Extension/Core/DataMapper/DataMapper.php index 1e98740d2eac6..1665ab3d201a8 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataMapper/DataMapper.php +++ b/src/Symfony/Component/Form/Extension/Core/DataMapper/DataMapper.php @@ -38,7 +38,7 @@ public function __construct(DataAccessorInterface $dataAccessor = null) /** * {@inheritdoc} */ - public function mapDataToForms($data, \Traversable $forms): void + public function mapDataToForms(mixed $data, \Traversable $forms): void { $empty = null === $data || [] === $data; diff --git a/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php b/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php index 11f54a9cd2a27..afdacf652831e 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php +++ b/src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php @@ -28,7 +28,7 @@ class RadioListMapper implements DataMapperInterface /** * {@inheritdoc} */ - public function mapDataToForms($choice, \Traversable $radios) + public function mapDataToForms(mixed $choice, \Traversable $radios) { if (!\is_string($choice)) { throw new UnexpectedTypeException($choice, 'string'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php index f79920971c015..0d9aaf0564593 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ArrayToPartsTransformer.php @@ -26,7 +26,7 @@ public function __construct(array $partMapping) $this->partMapping = $partMapping; } - public function transform($array) + public function transform(mixed $array) { if (null === $array) { $array = []; @@ -49,7 +49,7 @@ public function transform($array) return $result; } - public function reverseTransform($array) + public function reverseTransform(mixed $array) { if (!\is_array($array)) { throw new TransformationFailedException('Expected an array.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php index f4fd09b627fc9..ec93fbe990f5a 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/BooleanToStringTransformer.php @@ -48,7 +48,7 @@ public function __construct(string $trueValue, array $falseValues = [null]) * * @throws TransformationFailedException if the given value is not a Boolean */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return null; @@ -70,7 +70,7 @@ public function transform($value) * * @throws TransformationFailedException if the given value is not a string */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (\in_array($value, $this->falseValues, true)) { return false; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php index e1feafe62e1d3..f7e13ea6ffd3c 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoiceToValueTransformer.php @@ -27,12 +27,12 @@ public function __construct(ChoiceListInterface $choiceList) $this->choiceList = $choiceList; } - public function transform($choice) + public function transform(mixed $choice) { return (string) current($this->choiceList->getValuesForChoices([$choice])); } - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null !== $value && !\is_string($value)) { throw new TransformationFailedException('Expected a string or null.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php index 6c9e4fe9dc2b9..0b40a0fcd865b 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ChoicesToValuesTransformer.php @@ -32,7 +32,7 @@ public function __construct(ChoiceListInterface $choiceList) * * @throws TransformationFailedException if the given value is not an array */ - public function transform($array) + public function transform(mixed $array) { if (null === $array) { return []; @@ -52,7 +52,7 @@ public function transform($array) * or if no matching choice could be * found for some given value */ - public function reverseTransform($array) + public function reverseTransform(mixed $array) { if (null === $array) { return []; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php index 72d1586d499d1..55de5bdb5680d 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php @@ -47,7 +47,7 @@ public function __construct(array $transformers) * * @throws TransformationFailedException */ - public function transform($value) + public function transform(mixed $value) { foreach ($this->transformers as $transformer) { $value = $transformer->transform($value); @@ -71,7 +71,7 @@ public function transform($value) * * @throws TransformationFailedException */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { for ($i = \count($this->transformers) - 1; $i >= 0; --$i) { $value = $this->transformers[$i]->reverseTransform($value); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php index bb461bb3b0f3d..3d32a653c4587 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php @@ -64,7 +64,7 @@ public function __construct(array $fields = null, bool $pad = false) * * @throws UnexpectedTypeException if the given value is not a \DateInterval instance */ - public function transform($dateInterval) + public function transform(mixed $dateInterval) { if (null === $dateInterval) { return array_intersect_key( @@ -111,7 +111,7 @@ public function transform($dateInterval) * @throws UnexpectedTypeException if the given value is not an array * @throws TransformationFailedException if the value could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToStringTransformer.php index 8ae0cdb6664cf..9c22416a2a2cc 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToStringTransformer.php @@ -45,7 +45,7 @@ public function __construct(string $format = 'P%yY%mM%dDT%hH%iM%sS') * * @throws UnexpectedTypeException if the given value is not a \DateInterval instance */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return ''; @@ -67,7 +67,7 @@ public function transform($value) * @throws UnexpectedTypeException if the given value is not a string * @throws TransformationFailedException if the date interval could not be parsed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeImmutableToDateTimeTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeImmutableToDateTimeTransformer.php index 0ef9e22139072..5726147dbb483 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeImmutableToDateTimeTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeImmutableToDateTimeTransformer.php @@ -28,7 +28,7 @@ final class DateTimeImmutableToDateTimeTransformer implements DataTransformerInt * * @throws TransformationFailedException If the given value is not a \DateTimeImmutable */ - public function transform($value): ?\DateTime + public function transform(mixed $value): ?\DateTime { if (null === $value) { return null; @@ -48,7 +48,7 @@ public function transform($value): ?\DateTime * * @throws TransformationFailedException If the given value is not a \DateTime */ - public function reverseTransform($value): ?\DateTimeImmutable + public function reverseTransform(mixed $value): ?\DateTimeImmutable { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php index 2a4d10c0e3645..1d5cf3e612baa 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php @@ -54,7 +54,7 @@ public function __construct(string $inputTimezone = null, string $outputTimezone * * @throws TransformationFailedException If the given value is not a \DateTimeInterface */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return array_intersect_key([ @@ -110,7 +110,7 @@ public function transform($dateTime) * @throws TransformationFailedException If the given value is not an array, * if the value could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php index 3b2123bd96d85..1c2d1313cb54e 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php @@ -36,7 +36,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer * @throws TransformationFailedException If the given value is not an * instance of \DateTime or \DateTimeInterface */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return ''; @@ -71,7 +71,7 @@ public function transform($dateTime) * @throws TransformationFailedException If the given value is not a string, * if the value could not be transformed */ - public function reverseTransform($dateTimeLocal) + public function reverseTransform(mixed $dateTimeLocal) { if (!\is_string($dateTimeLocal)) { throw new TransformationFailedException('Expected a string.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php index 5dd5b498c6896..b1248e4858c35 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php @@ -75,7 +75,7 @@ public function __construct(string $inputTimezone = null, string $outputTimezone * @throws TransformationFailedException if the given value is not a \DateTimeInterface * or if the date could not be transformed */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return ''; @@ -104,7 +104,7 @@ public function transform($dateTime) * @throws TransformationFailedException if the given value is not a string, * if the date could not be parsed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (!\is_string($value)) { throw new TransformationFailedException('Expected a string.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php index a3437b895f9cb..a35d06aac5e98 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php @@ -27,7 +27,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer * * @throws TransformationFailedException If the given value is not a \DateTimeInterface */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return ''; @@ -58,7 +58,7 @@ public function transform($dateTime) * @throws TransformationFailedException If the given value is not a string, * if the value could not be transformed */ - public function reverseTransform($rfc3339) + public function reverseTransform(mixed $rfc3339) { if (!\is_string($rfc3339)) { throw new TransformationFailedException('Expected a string.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php index d27a8ff6c4ee7..ee691f41eea35 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php @@ -77,7 +77,7 @@ public function __construct(string $inputTimezone = null, string $outputTimezone * * @throws TransformationFailedException If the given value is not a \DateTimeInterface */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return ''; @@ -106,7 +106,7 @@ public function transform($dateTime) * @throws TransformationFailedException If the given value is not a string, * or could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (empty($value)) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php index 5a52038650e0c..11ba01abb7452 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php @@ -30,7 +30,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer * * @throws TransformationFailedException If the given value is not a \DateTimeInterface */ - public function transform($dateTime) + public function transform(mixed $dateTime) { if (null === $dateTime) { return null; @@ -53,7 +53,7 @@ public function transform($dateTime) * @throws TransformationFailedException If the given value is not a timestamp * or if the given timestamp is invalid */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeZoneToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeZoneToStringTransformer.php index 6dfccdfd3d1ba..407c4aa4e2a96 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeZoneToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeZoneToStringTransformer.php @@ -31,7 +31,7 @@ public function __construct(bool $multiple = false) /** * {@inheritdoc} */ - public function transform($dateTimeZone) + public function transform(mixed $dateTimeZone) { if (null === $dateTimeZone) { return null; @@ -55,7 +55,7 @@ public function transform($dateTimeZone) /** * {@inheritdoc} */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php index 2439e676c77de..04c20b54eefa4 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php @@ -36,7 +36,7 @@ public function __construct(?bool $grouping = false, ?int $roundingMode = \Numbe /** * {@inheritdoc} */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { $decimalSeparator = $this->getNumberFormatter()->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); @@ -52,7 +52,7 @@ public function reverseTransform($value) /** * @internal */ - protected function castParsedValue($value) + protected function castParsedValue(int|float $value): int|float { return $value; } diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php index aa4629f2efa15..afc7e9d66299b 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/IntlTimeZoneToStringTransformer.php @@ -31,7 +31,7 @@ public function __construct(bool $multiple = false) /** * {@inheritdoc} */ - public function transform($intlTimeZone) + public function transform(mixed $intlTimeZone) { if (null === $intlTimeZone) { return null; @@ -55,7 +55,7 @@ public function transform($intlTimeZone) /** * {@inheritdoc} */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php index 2cd4688b01956..7f79ebc38b4f6 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php @@ -52,7 +52,7 @@ public function __construct(?int $scale = 2, ?bool $grouping = true, ?int $round * @throws TransformationFailedException if the given value is not numeric or * if the value can not be transformed */ - public function transform($value) + public function transform(mixed $value) { if (null !== $value && 1 !== $this->divisor) { if (!is_numeric($value)) { @@ -74,7 +74,7 @@ public function transform($value) * @throws TransformationFailedException if the given value is not a string * or if the value can not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { $value = parent::reverseTransform($value); if (null !== $value && 1 !== $this->divisor) { diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index cbf1da1618798..9a215b47e2dca 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -56,7 +56,7 @@ public function __construct(int $scale = null, ?bool $grouping = false, ?int $ro * @throws TransformationFailedException if the given value is not numeric * or if the value can not be transformed */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return ''; @@ -89,7 +89,7 @@ public function transform($value) * @throws TransformationFailedException if the given value is not a string * or if the value can not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null !== $value && !\is_string($value)) { throw new TransformationFailedException('Expected a string.'); @@ -182,7 +182,7 @@ protected function getNumberFormatter() /** * @internal */ - protected function castParsedValue($value) + protected function castParsedValue(int|float $value): int|float { if (\is_int($value) && $value === (int) $float = (float) $value) { return $float; @@ -193,12 +193,8 @@ protected function castParsedValue($value) /** * Rounds a number according to the configured scale and rounding mode. - * - * @param int|float $number A number - * - * @return int|float The rounded number */ - private function round($number) + private function round(int|float $number): int|float { if (null !== $this->scale && null !== $this->roundingMode) { // shift number to maintain the correct scale during rounding diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php index 92ef2e299b70c..960201bd915e9 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php @@ -76,7 +76,7 @@ public function __construct(int $scale = null, string $type = null, int $roundin * @throws TransformationFailedException if the given value is not numeric or * if the value could not be transformed */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return ''; @@ -111,7 +111,7 @@ public function transform($value) * @throws TransformationFailedException if the given value is not a string or * if the value could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (!\is_string($value)) { throw new TransformationFailedException('Expected a string.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/StringToFloatTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/StringToFloatTransformer.php index 27e60b4306336..da50887cc5742 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/StringToFloatTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/StringToFloatTransformer.php @@ -28,7 +28,7 @@ public function __construct(int $scale = null) * * @return float|null */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return null; @@ -46,7 +46,7 @@ public function transform($value) * * @return string|null */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/UlidToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/UlidToStringTransformer.php index ea3fdec341ea9..242db09099aed 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/UlidToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/UlidToStringTransformer.php @@ -31,7 +31,7 @@ class UlidToStringTransformer implements DataTransformerInterface * * @throws TransformationFailedException If the given value is not a Ulid object */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return null; @@ -54,7 +54,7 @@ public function transform($value) * @throws TransformationFailedException If the given value is not a string, * or could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value || '' === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php index a019847ae4adc..a992967d5f6a1 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/UuidToStringTransformer.php @@ -31,7 +31,7 @@ class UuidToStringTransformer implements DataTransformerInterface * * @throws TransformationFailedException If the given value is not a Uuid object */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return null; @@ -54,7 +54,7 @@ public function transform($value) * @throws TransformationFailedException If the given value is not a string, * or could not be transformed */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value || '' === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php index 4f04645eb77d7..3bd7419c71c61 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php @@ -29,11 +29,9 @@ public function __construct(array $keys) /** * Duplicates the given value through the array. * - * @param mixed $value The value - * * @return array The array */ - public function transform($value) + public function transform(mixed $value) { $result = []; @@ -47,12 +45,10 @@ public function transform($value) /** * Extracts the duplicated value from an array. * - * @return mixed The value - * * @throws TransformationFailedException if the given value is not an array or * if the given array can not be transformed */ - public function reverseTransform($array) + public function reverseTransform(mixed $array) { if (!\is_array($array)) { throw new TransformationFailedException('Expected an array.'); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/WeekToArrayTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/WeekToArrayTransformer.php index 37405998fa428..3c4d4807211a8 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/WeekToArrayTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/WeekToArrayTransformer.php @@ -31,7 +31,7 @@ class WeekToArrayTransformer implements DataTransformerInterface * @throws TransformationFailedException If the given value is not a string, * or if the given value does not follow the right format */ - public function transform($value) + public function transform(mixed $value) { if (null === $value) { return ['year' => null, 'week' => null]; @@ -61,7 +61,7 @@ public function transform($value) * @throws TransformationFailedException If the given value can not be merged in a valid week date string, * or if the obtained week date does not exists */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { if (null === $value || [] === $value) { return null; diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php index 813456b95e2a6..940ce39203655 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php @@ -31,12 +31,7 @@ class ResizeFormListener implements EventSubscriberInterface private $deleteEmpty; - /** - * @param bool $allowAdd Whether children could be added to the group - * @param bool $allowDelete Whether children could be removed from the group - * @param bool|callable $deleteEmpty - */ - public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, $deleteEmpty = false) + public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, bool|callable $deleteEmpty = false) { $this->type = $type; $this->allowAdd = $allowAdd; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 6868afc562ce2..ab9413a563b90 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -210,10 +210,8 @@ private static function getMaxFilesize() * (i.e. try "MB", then "kB", then "bytes"). * * This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes(). - * - * @param int|float $limit */ - private function factorizeSizes(int $size, $limit) + private function factorizeSizes(int $size, int|float $limit) { $coef = self::MIB_BYTES; $coefFactor = self::KIB_BYTES; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TextType.php b/src/Symfony/Component/Form/Extension/Core/Type/TextType.php index 9b3c59db85bb4..11e63f59be024 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TextType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TextType.php @@ -51,7 +51,7 @@ public function getBlockPrefix() /** * {@inheritdoc} */ - public function transform($data) + public function transform(mixed $data) { // Model data should not be transformed return $data; @@ -60,7 +60,7 @@ public function transform($data) /** * {@inheritdoc} */ - public function reverseTransform($data) + public function reverseTransform(mixed $data) { return null === $data ? '' : $data; } diff --git a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php index 05503ff52977f..c62932cee5418 100644 --- a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php +++ b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php @@ -38,7 +38,7 @@ public function __construct(ServerParams $serverParams = null) /** * {@inheritdoc} */ - public function handleRequest(FormInterface $form, $request = null) + public function handleRequest(FormInterface $form, mixed $request = null) { if (!$request instanceof Request) { throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request'); @@ -112,7 +112,7 @@ public function handleRequest(FormInterface $form, $request = null) /** * {@inheritdoc} */ - public function isFileUpload($data) + public function isFileUpload(mixed $data) { return $data instanceof File; } @@ -120,7 +120,7 @@ public function isFileUpload($data) /** * @return int|null */ - public function getUploadFileError($data) + public function getUploadFileError(mixed $data) { if (!$data instanceof UploadedFile || $data->isValid()) { return null; diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index d14055f16cc3d..c669d56b8708a 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -29,7 +29,7 @@ class FormValidator extends ConstraintValidator /** * {@inheritdoc} */ - public function validate($form, Constraint $formConstraint) + public function validate(mixed $form, Constraint $formConstraint) { if (!$formConstraint instanceof Form) { throw new UnexpectedTypeException($formConstraint, Form::class); @@ -246,7 +246,7 @@ private function getValidationGroups(FormInterface $form) * * @return GroupSequence|array The validation groups */ - private static function resolveValidationGroups($groups, FormInterface $form) + private static function resolveValidationGroups(string|GroupSequence|array|callable $groups, FormInterface $form): GroupSequence|array { if (!\is_string($groups) && \is_callable($groups)) { $groups = $groups($form); @@ -259,10 +259,18 @@ private static function resolveValidationGroups($groups, FormInterface $form) return (array) $groups; } - private static function getConstraintsInGroups($constraints, $group) + private static function getConstraintsInGroups(array $constraints, string|array $group): array { - return array_filter($constraints, static function (Constraint $constraint) use ($group) { - return \in_array($group, $constraint->groups, true); + $groups = (array) $group; + + 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; }); } } diff --git a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php index 97e16caea8f70..72b98f5451438 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php +++ b/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php @@ -259,7 +259,7 @@ public function guessPatternForConstraint(Constraint $constraint) * * @return Guess|null The guessed value with the highest confidence */ - protected function guess(string $class, string $property, \Closure $closure, $defaultValue = null) + protected function guess(string $class, string $property, \Closure $closure, mixed $defaultValue = null) { $guesses = []; $classMetadata = $this->metadataFactory->getMetadataFor($class); diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 82bd8a660b9ee..985b6a917442f 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -304,7 +304,7 @@ public function isRoot() /** * {@inheritdoc} */ - public function setData($modelData) + public function setData(mixed $modelData) { // If the form is submitted while disabled, it is set to submitted, but the data is not // changed. In such cases (i.e. when the form is not initialized yet) don't @@ -485,7 +485,7 @@ public function initialize() /** * {@inheritdoc} */ - public function handleRequest($request = null) + public function handleRequest(mixed $request = null) { $this->config->getRequestHandler()->handleRequest($this, $request); @@ -495,7 +495,7 @@ public function handleRequest($request = null) /** * {@inheritdoc} */ - public function submit($submittedData, bool $clearMissing = true) + public function submit(mixed $submittedData, bool $clearMissing = true) { if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once.'); @@ -831,7 +831,7 @@ public function all() /** * {@inheritdoc} */ - public function add($child, string $type = null, array $options = []) + public function add(FormInterface|string $child, string $type = null, array $options = []) { if ($this->submitted) { throw new AlreadySubmittedException('You cannot add children to a submitted form.'); @@ -946,7 +946,7 @@ public function get(string $name) * * @return bool */ - public function offsetExists($name) + public function offsetExists(mixed $name) { return $this->has($name); } @@ -960,7 +960,7 @@ public function offsetExists($name) * * @throws OutOfBoundsException if the named child does not exist */ - public function offsetGet($name) + public function offsetGet(mixed $name) { return $this->get($name); } @@ -976,7 +976,7 @@ public function offsetGet($name) * * @see self::add() */ - public function offsetSet($name, $child) + public function offsetSet(mixed $name, mixed $child) { $this->add($child); } @@ -988,7 +988,7 @@ public function offsetSet($name, $child) * * @throws AlreadySubmittedException if the form has already been submitted */ - public function offsetUnset($name) + public function offsetUnset(mixed $name) { $this->remove($name); } @@ -1075,7 +1075,7 @@ private function sort(array &$children): void * * @throws TransformationFailedException If the underlying data cannot be transformed to "normalized" format */ - private function modelToNorm($value) + private function modelToNorm(mixed $value) { try { foreach ($this->config->getModelTransformers() as $transformer) { @@ -1095,7 +1095,7 @@ private function modelToNorm($value) * * @throws TransformationFailedException If the value cannot be transformed to "model" format */ - private function normToModel($value) + private function normToModel(mixed $value) { try { $transformers = $this->config->getModelTransformers(); @@ -1117,7 +1117,7 @@ private function normToModel($value) * * @throws TransformationFailedException If the normalized value cannot be transformed to "view" format */ - private function normToView($value) + private function normToView(mixed $value) { // Scalar values should be converted to strings to // facilitate differentiation between empty ("") and zero (0). @@ -1146,7 +1146,7 @@ private function normToView($value) * * @throws TransformationFailedException If the submitted value cannot be transformed to "normalized" format */ - private function viewToNorm($value) + private function viewToNorm(mixed $value) { if (!$transformers = $this->config->getViewTransformers()) { return '' === $value ? null : $value; diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index 8c92046ee3590..89e959130f3fa 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -47,7 +47,7 @@ public function __construct(?string $name, ?string $dataClass, EventDispatcherIn /** * {@inheritdoc} */ - public function add($child, string $type = null, array $options = []) + public function add(FormBuilderInterface|string $child, string $type = null, array $options = []) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -80,7 +80,7 @@ public function add($child, string $type = null, array $options = []) /** * {@inheritdoc} */ - public function create($name, string $type = null, array $options = []) + public function create(string $name, string $type = null, array $options = []) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -100,7 +100,7 @@ public function create($name, string $type = null, array $options = []) /** * {@inheritdoc} */ - public function get($name) + public function get(string $name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -120,7 +120,7 @@ public function get($name) /** * {@inheritdoc} */ - public function remove($name) + public function remove(string $name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -134,7 +134,7 @@ public function remove($name) /** * {@inheritdoc} */ - public function has($name) + public function has(string $name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); diff --git a/src/Symfony/Component/Form/FormBuilderInterface.php b/src/Symfony/Component/Form/FormBuilderInterface.php index d95a528bb5ce1..e3f5028d60d5b 100644 --- a/src/Symfony/Component/Form/FormBuilderInterface.php +++ b/src/Symfony/Component/Form/FormBuilderInterface.php @@ -25,12 +25,11 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild * If you add a nested group, this group should also be represented in the * object hierarchy. * - * @param string|FormBuilderInterface $child - * @param array $options + * @param array $options * * @return self */ - public function add($child, string $type = null, array $options = []); + public function add(string|FormBuilderInterface $child, string $type = null, array $options = []); /** * Creates a form builder. diff --git a/src/Symfony/Component/Form/FormConfigBuilder.php b/src/Symfony/Component/Form/FormConfigBuilder.php index 69acee4d9900a..caa5cc078905d 100644 --- a/src/Symfony/Component/Form/FormConfigBuilder.php +++ b/src/Symfony/Component/Form/FormConfigBuilder.php @@ -362,7 +362,7 @@ public function hasAttribute(string $name) /** * {@inheritdoc} */ - public function getAttribute(string $name, $default = null) + public function getAttribute(string $name, mixed $default = null) { return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default; } @@ -457,7 +457,7 @@ public function hasOption(string $name) /** * {@inheritdoc} */ - public function getOption(string $name, $default = null) + public function getOption(string $name, mixed $default = null) { return \array_key_exists($name, $this->options) ? $this->options[$name] : $default; } @@ -473,7 +473,7 @@ public function getIsEmptyCallback(): ?callable /** * {@inheritdoc} */ - public function setAttribute(string $name, $value) + public function setAttribute(string $name, mixed $value) { if ($this->locked) { throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -529,7 +529,7 @@ public function setDisabled(bool $disabled) /** * {@inheritdoc} */ - public function setEmptyData($emptyData) + public function setEmptyData(mixed $emptyData) { if ($this->locked) { throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -571,7 +571,7 @@ public function setRequired(bool $required) /** * {@inheritdoc} */ - public function setPropertyPath($propertyPath) + public function setPropertyPath(string|PropertyPathInterface|null $propertyPath) { if ($this->locked) { throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); @@ -659,7 +659,7 @@ public function setType(ResolvedFormTypeInterface $type) /** * {@inheritdoc} */ - public function setData($data) + public function setData(mixed $data) { if ($this->locked) { throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); diff --git a/src/Symfony/Component/Form/FormConfigBuilderInterface.php b/src/Symfony/Component/Form/FormConfigBuilderInterface.php index fb4a835ba6b9d..05d527480b7ce 100644 --- a/src/Symfony/Component/Form/FormConfigBuilderInterface.php +++ b/src/Symfony/Component/Form/FormConfigBuilderInterface.php @@ -86,7 +86,7 @@ public function resetModelTransformers(); * * @return $this The configuration object */ - public function setAttribute(string $name, $value); + public function setAttribute(string $name, mixed $value); /** * Sets the attributes. @@ -116,7 +116,7 @@ public function setDisabled(bool $disabled); * * @return $this The configuration object */ - public function setEmptyData($emptyData); + public function setEmptyData(mixed $emptyData); /** * Sets whether errors bubble up to the parent. @@ -140,7 +140,7 @@ public function setRequired(bool $required); * * @return $this The configuration object */ - public function setPropertyPath($propertyPath); + public function setPropertyPath(string|PropertyPathInterface|null $propertyPath); /** * Sets whether the form should be mapped to an element of its @@ -187,7 +187,7 @@ public function setType(ResolvedFormTypeInterface $type); * * @return $this The configuration object */ - public function setData($data); + public function setData(mixed $data); /** * Locks the form's data to the data passed in the configuration. diff --git a/src/Symfony/Component/Form/FormConfigInterface.php b/src/Symfony/Component/Form/FormConfigInterface.php index e012b780b3a87..c1ee87d41a698 100644 --- a/src/Symfony/Component/Form/FormConfigInterface.php +++ b/src/Symfony/Component/Form/FormConfigInterface.php @@ -156,11 +156,9 @@ public function hasAttribute(string $name); /** * Returns the value of the given attribute. * - * @param mixed $default The value returned if the attribute does not exist - * * @return mixed The attribute value */ - public function getAttribute(string $name, $default = null); + public function getAttribute(string $name, mixed $default = null); /** * Returns the initial data of the form. @@ -240,11 +238,9 @@ public function hasOption(string $name); /** * Returns the value of a specific option. * - * @param mixed $default The value returned if the option does not exist - * * @return mixed The option value */ - public function getOption(string $name, $default = null); + public function getOption(string $name, mixed $default = null); /** * Returns a callable that takes the model data as argument and that returns if it is empty or not. diff --git a/src/Symfony/Component/Form/FormError.php b/src/Symfony/Component/Form/FormError.php index 8ea67c4412558..8d5c571bfc560 100644 --- a/src/Symfony/Component/Form/FormError.php +++ b/src/Symfony/Component/Form/FormError.php @@ -47,7 +47,7 @@ class FormError * * @see \Symfony\Component\Translation\Translator */ - public function __construct(string $message, string $messageTemplate = null, array $messageParameters = [], int $messagePluralization = null, $cause = null) + public function __construct(string $message, string $messageTemplate = null, array $messageParameters = [], int $messagePluralization = null, mixed $cause = null) { $this->message = $message; $this->messageTemplate = $messageTemplate ?: $message; diff --git a/src/Symfony/Component/Form/FormErrorIterator.php b/src/Symfony/Component/Form/FormErrorIterator.php index 3943278ac30e3..dc58ce5d3397e 100644 --- a/src/Symfony/Component/Form/FormErrorIterator.php +++ b/src/Symfony/Component/Form/FormErrorIterator.php @@ -142,7 +142,7 @@ public function rewind() * * @return bool Whether that position exists */ - public function offsetExists($position) + public function offsetExists(mixed $position) { return isset($this->errors[$position]); } @@ -156,7 +156,7 @@ public function offsetExists($position) * * @throws OutOfBoundsException If the given position does not exist */ - public function offsetGet($position) + public function offsetGet(mixed $position) { if (!isset($this->errors[$position])) { throw new OutOfBoundsException('The offset '.$position.' does not exist.'); @@ -170,7 +170,7 @@ public function offsetGet($position) * * @throws BadMethodCallException */ - public function offsetSet($position, $value) + public function offsetSet(mixed $position, mixed $value) { throw new BadMethodCallException('The iterator doesn\'t support modification of elements.'); } @@ -180,7 +180,7 @@ public function offsetSet($position, $value) * * @throws BadMethodCallException */ - public function offsetUnset($position) + public function offsetUnset(mixed $position) { throw new BadMethodCallException('The iterator doesn\'t support modification of elements.'); } @@ -229,11 +229,9 @@ public function count() /** * Sets the position of the iterator. * - * @param int $position The new position - * * @throws OutOfBoundsException If the position is invalid */ - public function seek($position) + public function seek(int $position) { if (!isset($this->errors[$position])) { throw new OutOfBoundsException('The offset '.$position.' does not exist.'); @@ -253,7 +251,7 @@ public function seek($position) * * @return static new instance which contains only specific errors */ - public function findByCodes($codes) + public function findByCodes(string|array $codes) { $codes = (array) $codes; $errors = []; diff --git a/src/Symfony/Component/Form/FormEvent.php b/src/Symfony/Component/Form/FormEvent.php index c466fafdc6d9e..b50e637b058d3 100644 --- a/src/Symfony/Component/Form/FormEvent.php +++ b/src/Symfony/Component/Form/FormEvent.php @@ -21,10 +21,7 @@ class FormEvent extends Event private $form; protected $data; - /** - * @param mixed $data The data - */ - public function __construct(FormInterface $form, $data) + public function __construct(FormInterface $form, mixed $data) { $this->form = $form; $this->data = $data; @@ -52,10 +49,8 @@ public function getData() /** * Allows updating with some filtered data. - * - * @param mixed $data */ - public function setData($data) + public function setData(mixed $data) { $this->data = $data; } diff --git a/src/Symfony/Component/Form/FormFactory.php b/src/Symfony/Component/Form/FormFactory.php index 5e7e807333045..d518e2ff15b7e 100644 --- a/src/Symfony/Component/Form/FormFactory.php +++ b/src/Symfony/Component/Form/FormFactory.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Form; +use Symfony\Component\Form\Extension\Core\Type\FormType; + class FormFactory implements FormFactoryInterface { private $registry; @@ -23,7 +25,7 @@ public function __construct(FormRegistryInterface $registry) /** * {@inheritdoc} */ - public function create(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []) + public function create(string $type = FormType::class, mixed $data = null, array $options = []) { return $this->createBuilder($type, $data, $options)->getForm(); } @@ -31,7 +33,7 @@ public function create(string $type = 'Symfony\Component\Form\Extension\Core\Typ /** * {@inheritdoc} */ - public function createNamed(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []) + public function createNamed(string $name, string $type = FormType::class, mixed $data = null, array $options = []) { return $this->createNamedBuilder($name, $type, $data, $options)->getForm(); } @@ -39,7 +41,7 @@ public function createNamed(string $name, string $type = 'Symfony\Component\Form /** * {@inheritdoc} */ - public function createForProperty(string $class, string $property, $data = null, array $options = []) + public function createForProperty(string $class, string $property, mixed $data = null, array $options = []) { return $this->createBuilderForProperty($class, $property, $data, $options)->getForm(); } @@ -47,7 +49,7 @@ public function createForProperty(string $class, string $property, $data = null, /** * {@inheritdoc} */ - public function createBuilder(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []) + public function createBuilder(string $type = FormType::class, mixed $data = null, array $options = []) { return $this->createNamedBuilder($this->registry->getType($type)->getBlockPrefix(), $type, $data, $options); } @@ -55,7 +57,7 @@ public function createBuilder(string $type = 'Symfony\Component\Form\Extension\C /** * {@inheritdoc} */ - public function createNamedBuilder(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []) + public function createNamedBuilder(string $name, string $type = FormType::class, mixed $data = null, array $options = []) { if (null !== $data && !\array_key_exists('data', $options)) { $options['data'] = $data; @@ -75,7 +77,7 @@ public function createNamedBuilder(string $name, string $type = 'Symfony\Compone /** * {@inheritdoc} */ - public function createBuilderForProperty(string $class, string $property, $data = null, array $options = []) + public function createBuilderForProperty(string $class, string $property, mixed $data = null, array $options = []) { if (null === $guesser = $this->registry->getTypeGuesser()) { return $this->createNamedBuilder($property, 'Symfony\Component\Form\Extension\Core\Type\TextType', $data, $options); diff --git a/src/Symfony/Component/Form/FormFactoryInterface.php b/src/Symfony/Component/Form/FormFactoryInterface.php index 2f1acf5424e4c..77b8309a8f251 100644 --- a/src/Symfony/Component/Form/FormFactoryInterface.php +++ b/src/Symfony/Component/Form/FormFactoryInterface.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Form; +use Symfony\Component\Form\Extension\Core\Type\FormType; + /** * Allows creating a form based on a name, a class or a property. * @@ -29,7 +31,7 @@ interface FormFactoryInterface * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ - public function create(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []); + public function create(string $type = FormType::class, mixed $data = null, array $options = []); /** * Returns a form. @@ -42,7 +44,7 @@ public function create(string $type = 'Symfony\Component\Form\Extension\Core\Typ * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ - public function createNamed(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []); + public function createNamed(string $name, string $type = FormType::class, mixed $data = null, array $options = []); /** * Returns a form for a property of a class. @@ -57,7 +59,7 @@ public function createNamed(string $name, string $type = 'Symfony\Component\Form * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type */ - public function createForProperty(string $class, string $property, $data = null, array $options = []); + public function createForProperty(string $class, string $property, mixed $data = null, array $options = []); /** * Returns a form builder. @@ -68,7 +70,7 @@ public function createForProperty(string $class, string $property, $data = null, * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ - public function createBuilder(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []); + public function createBuilder(string $type = FormType::class, mixed $data = null, array $options = []); /** * Returns a form builder. @@ -79,7 +81,7 @@ public function createBuilder(string $type = 'Symfony\Component\Form\Extension\C * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ - public function createNamedBuilder(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []); + public function createNamedBuilder(string $name, string $type = FormType::class, mixed $data = null, array $options = []); /** * Returns a form builder for a property of a class. @@ -95,5 +97,5 @@ public function createNamedBuilder(string $name, string $type = 'Symfony\Compone * * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type */ - public function createBuilderForProperty(string $class, string $property, $data = null, array $options = []); + public function createBuilderForProperty(string $class, string $property, mixed $data = null, array $options = []); } diff --git a/src/Symfony/Component/Form/FormInterface.php b/src/Symfony/Component/Form/FormInterface.php index 25e9561d5c599..7e8e43bdc97a7 100644 --- a/src/Symfony/Component/Form/FormInterface.php +++ b/src/Symfony/Component/Form/FormInterface.php @@ -53,7 +53,7 @@ public function getParent(); * @throws Exception\LogicException when trying to add a child to a non-compound form * @throws Exception\UnexpectedTypeException if $child or $type has an unexpected type */ - public function add($child, string $type = null, array $options = []); + public function add(FormInterface|string $child, string $type = null, array $options = []); /** * Returns the child with the given name. @@ -113,7 +113,7 @@ public function getErrors(bool $deep = false, bool $flatten = true); * the form inherits data from its parent * @throws Exception\TransformationFailedException if the synchronization failed */ - public function setData($modelData); + public function setData(mixed $modelData); /** * Returns the model data in the format needed for the underlying object. @@ -284,11 +284,9 @@ public function initialize(); * {@link RequestHandlerInterface} instance, which determines whether to * submit the form or not. * - * @param mixed $request The request to handle - * * @return $this */ - public function handleRequest($request = null); + public function handleRequest(mixed $request = null); /** * Submits data to the form. @@ -303,7 +301,7 @@ public function handleRequest($request = null); * * @throws Exception\AlreadySubmittedException if the form has already been submitted */ - public function submit($submittedData, bool $clearMissing = true); + public function submit(string|array|null $submittedData, bool $clearMissing = true); /** * Returns the root of the form tree. diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 2f8f35199098e..48f3841f24061 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -48,7 +48,7 @@ public function getEngine() /** * {@inheritdoc} */ - public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true) + public function setTheme(FormView $view, mixed $themes, bool $useDefaultThemes = true) { $this->engine->setTheme($view, $themes, $useDefaultThemes); } diff --git a/src/Symfony/Component/Form/FormRendererEngineInterface.php b/src/Symfony/Component/Form/FormRendererEngineInterface.php index 2dd2a2fc59f20..9009ba39b22c9 100644 --- a/src/Symfony/Component/Form/FormRendererEngineInterface.php +++ b/src/Symfony/Component/Form/FormRendererEngineInterface.php @@ -25,7 +25,7 @@ interface FormRendererEngineInterface * @param mixed $themes The theme(s). The type of these themes * is open to the implementation. */ - public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true); + public function setTheme(FormView $view, mixed $themes, bool $useDefaultThemes = true); /** * Returns the resource for a block name. @@ -132,5 +132,5 @@ public function getResourceHierarchyLevel(FormView $view, array $blockNameHierar * * @return string The HTML markup */ - public function renderBlock(FormView $view, $resource, string $blockName, array $variables = []); + public function renderBlock(FormView $view, mixed $resource, string $blockName, array $variables = []); } diff --git a/src/Symfony/Component/Form/FormRendererInterface.php b/src/Symfony/Component/Form/FormRendererInterface.php index 16c29744edd97..0d0ad7267440c 100644 --- a/src/Symfony/Component/Form/FormRendererInterface.php +++ b/src/Symfony/Component/Form/FormRendererInterface.php @@ -34,7 +34,7 @@ public function getEngine(); * @param bool $useDefaultThemes If true, will use default themes specified * in the renderer */ - public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true); + public function setTheme(FormView $view, mixed $themes, bool $useDefaultThemes = true); /** * Renders a named block of the form theme. diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 78656b3868211..dbe0f618170db 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -108,7 +108,7 @@ public function setMethodRendered() * * @return self The child view */ - public function offsetGet($name) + public function offsetGet(mixed $name) { return $this->children[$name]; } @@ -120,7 +120,7 @@ public function offsetGet($name) * * @return bool Whether the child view exists */ - public function offsetExists($name) + public function offsetExists(mixed $name) { return isset($this->children[$name]); } @@ -130,7 +130,7 @@ public function offsetExists($name) * * @throws BadMethodCallException always as setting a child by name is not allowed */ - public function offsetSet($name, $value) + public function offsetSet(mixed $name, mixed $value) { throw new BadMethodCallException('Not supported.'); } @@ -140,7 +140,7 @@ public function offsetSet($name, $value) * * @param string $name The child name */ - public function offsetUnset($name) + public function offsetUnset(mixed $name) { unset($this->children[$name]); } diff --git a/src/Symfony/Component/Form/Guess/ValueGuess.php b/src/Symfony/Component/Form/Guess/ValueGuess.php index fe19dfeb04e4a..a316a0adade92 100644 --- a/src/Symfony/Component/Form/Guess/ValueGuess.php +++ b/src/Symfony/Component/Form/Guess/ValueGuess.php @@ -21,11 +21,9 @@ class ValueGuess extends Guess private $value; /** - * @param string|int|bool|null $value The guessed value - * @param int $confidence The confidence that the guessed class name - * is correct + * @param int $confidence The confidence that the guessed class name is correct */ - public function __construct($value, int $confidence) + public function __construct(string|int|bool|null $value, int $confidence) { parent::__construct($confidence); diff --git a/src/Symfony/Component/Form/NativeRequestHandler.php b/src/Symfony/Component/Form/NativeRequestHandler.php index 6b18df44a165d..0dba25c659901 100644 --- a/src/Symfony/Component/Form/NativeRequestHandler.php +++ b/src/Symfony/Component/Form/NativeRequestHandler.php @@ -44,7 +44,7 @@ public function __construct(ServerParams $params = null) * * @throws Exception\UnexpectedTypeException If the $request is not null */ - public function handleRequest(FormInterface $form, $request = null) + public function handleRequest(FormInterface $form, mixed $request = null) { if (null !== $request) { throw new UnexpectedTypeException($request, 'null'); @@ -127,7 +127,7 @@ public function handleRequest(FormInterface $form, $request = null) /** * {@inheritdoc} */ - public function isFileUpload($data) + public function isFileUpload(mixed $data) { // POST data will always be strings or arrays of strings. Thus, we can be sure // that the submitted data is a file upload if the "error" value is an integer @@ -138,7 +138,7 @@ public function isFileUpload($data) /** * @return int|null */ - public function getUploadFileError($data) + public function getUploadFileError(mixed $data) { if (!\is_array($data)) { return null; @@ -192,7 +192,7 @@ private static function getRequestMethod(): string * * @return mixed */ - private static function fixPhpFilesArray($data) + private static function fixPhpFilesArray(mixed $data) { if (!\is_array($data)) { return $data; @@ -228,7 +228,7 @@ private static function fixPhpFilesArray($data) * * @return mixed Returns the stripped upload data */ - private static function stripEmptyFiles($data) + private static function stripEmptyFiles(mixed $data) { if (!\is_array($data)) { return $data; diff --git a/src/Symfony/Component/Form/RequestHandlerInterface.php b/src/Symfony/Component/Form/RequestHandlerInterface.php index 65d86e224679e..2cb671df71ee7 100644 --- a/src/Symfony/Component/Form/RequestHandlerInterface.php +++ b/src/Symfony/Component/Form/RequestHandlerInterface.php @@ -20,17 +20,13 @@ interface RequestHandlerInterface { /** * Submits a form if it was submitted. - * - * @param mixed $request The current request */ - public function handleRequest(FormInterface $form, $request = null); + public function handleRequest(FormInterface $form, mixed $request = null); /** * Returns true if the given data is a file upload. * - * @param mixed $data The form field data - * * @return bool */ - public function isFileUpload($data); + public function isFileUpload(mixed $data); } diff --git a/src/Symfony/Component/Form/ReversedTransformer.php b/src/Symfony/Component/Form/ReversedTransformer.php index 8089e47bf0554..0591c4f3b07ae 100644 --- a/src/Symfony/Component/Form/ReversedTransformer.php +++ b/src/Symfony/Component/Form/ReversedTransformer.php @@ -31,7 +31,7 @@ public function __construct(DataTransformerInterface $reversedTransformer) /** * {@inheritdoc} */ - public function transform($value) + public function transform(mixed $value) { return $this->reversedTransformer->reverseTransform($value); } @@ -39,7 +39,7 @@ public function transform($value) /** * {@inheritdoc} */ - public function reverseTransform($value) + public function reverseTransform(mixed $value) { return $this->reversedTransformer->transform($value); } diff --git a/src/Symfony/Component/Form/SubmitButton.php b/src/Symfony/Component/Form/SubmitButton.php index 5e38b10987282..0312e56bd6b72 100644 --- a/src/Symfony/Component/Form/SubmitButton.php +++ b/src/Symfony/Component/Form/SubmitButton.php @@ -31,14 +31,11 @@ public function isClicked() /** * Submits data to the button. * - * @param string|null $submittedData The data - * @param bool $clearMissing Not used - * * @return $this * * @throws Exception\AlreadySubmittedException if the form has already been submitted */ - public function submit($submittedData, bool $clearMissing = true) + public function submit(array|string|null $submittedData, bool $clearMissing = true) { if ($this->getConfig()->getDisabled()) { $this->clicked = false; diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 69b71bcc7751c..c937f01954d54 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -54,12 +54,6 @@ public function testNoSetName() $this->assertFalse(method_exists($this->builder, 'setName')); } - public function testAddNameNoStringAndNoInteger() - { - $this->expectException(UnexpectedTypeException::class); - $this->builder->add(true); - } - public function testAddWithGuessFluent() { $this->builder = new FormBuilder('name', 'stdClass', $this->dispatcher, $this->factory); diff --git a/src/Symfony/Component/Form/Tests/VersionAwareTest.php b/src/Symfony/Component/Form/Tests/VersionAwareTest.php index c555b2499d5c9..9ab4797b3083d 100644 --- a/src/Symfony/Component/Form/Tests/VersionAwareTest.php +++ b/src/Symfony/Component/Form/Tests/VersionAwareTest.php @@ -15,10 +15,7 @@ trait VersionAwareTest { protected static $supportedFeatureSetVersion = 404; - /** - * @param int $requiredFeatureSetVersion - */ - protected function requiresFeatureSet($requiredFeatureSetVersion) + protected function requiresFeatureSet(int $requiredFeatureSetVersion) { if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) { $this->markTestSkipped(sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100)); diff --git a/src/Symfony/Component/Form/Util/FormUtil.php b/src/Symfony/Component/Form/Util/FormUtil.php index fed96de4fa9b3..9dbbfc7bc74a5 100644 --- a/src/Symfony/Component/Form/Util/FormUtil.php +++ b/src/Symfony/Component/Form/Util/FormUtil.php @@ -30,11 +30,9 @@ private function __construct() * a form and needs to be consistent. PHP keyword `empty` cannot * be used as it also considers 0 and "0" to be empty. * - * @param mixed $data - * * @return bool */ - public static function isEmpty($data) + public static function isEmpty(mixed $data) { // Should not do a check for [] === $data!!! // This method is used in occurrences where arrays are diff --git a/src/Symfony/Component/Form/Util/OptionsResolverWrapper.php b/src/Symfony/Component/Form/Util/OptionsResolverWrapper.php index b5f29ac5100f2..03a90cda7f799 100644 --- a/src/Symfony/Component/Form/Util/OptionsResolverWrapper.php +++ b/src/Symfony/Component/Form/Util/OptionsResolverWrapper.php @@ -41,7 +41,7 @@ public function setNormalizer(string $option, \Closure $normalizer): self /** * @return $this */ - public function setAllowedValues(string $option, $allowedValues): self + public function setAllowedValues(string $option, mixed $allowedValues): self { try { parent::setAllowedValues($option, $allowedValues); @@ -55,7 +55,7 @@ public function setAllowedValues(string $option, $allowedValues): self /** * @return $this */ - public function addAllowedValues(string $option, $allowedValues): self + public function addAllowedValues(string $option, mixed $allowedValues): self { try { parent::addAllowedValues($option, $allowedValues); @@ -67,6 +67,8 @@ public function addAllowedValues(string $option, $allowedValues): self } /** + * @param string|array $allowedTypes + * * @return $this */ public function setAllowedTypes(string $option, $allowedTypes): self @@ -81,6 +83,8 @@ public function setAllowedTypes(string $option, $allowedTypes): self } /** + * @param string|array $allowedTypes + * * @return $this */ public function addAllowedTypes(string $option, $allowedTypes): self diff --git a/src/Symfony/Component/Form/Util/OrderedHashMap.php b/src/Symfony/Component/Form/Util/OrderedHashMap.php index 6d758ca91c5d4..b8b1bf5e83887 100644 --- a/src/Symfony/Component/Form/Util/OrderedHashMap.php +++ b/src/Symfony/Component/Form/Util/OrderedHashMap.php @@ -101,7 +101,7 @@ public function __construct(array $elements = []) /** * @return bool */ - public function offsetExists($key) + public function offsetExists(mixed $key) { return isset($this->elements[$key]); } @@ -109,7 +109,7 @@ public function offsetExists($key) /** * {@inheritdoc} */ - public function offsetGet($key) + public function offsetGet(mixed $key) { if (!isset($this->elements[$key])) { throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $key)); @@ -121,7 +121,7 @@ public function offsetGet($key) /** * {@inheritdoc} */ - public function offsetSet($key, $value) + public function offsetSet(mixed $key, mixed $value) { if (null === $key || !isset($this->elements[$key])) { if (null === $key) { @@ -142,7 +142,7 @@ public function offsetSet($key, $value) /** * {@inheritdoc} */ - public function offsetUnset($key) + public function offsetUnset(mixed $key) { if (false !== ($position = array_search((string) $key, $this->orderedKeys))) { array_splice($this->orderedKeys, $position, 1); diff --git a/src/Symfony/Component/Validator/Constraints/GroupSequence.php b/src/Symfony/Component/Validator/Constraints/GroupSequence.php index 379c763391cff..4ed082b9c1537 100644 --- a/src/Symfony/Component/Validator/Constraints/GroupSequence.php +++ b/src/Symfony/Component/Validator/Constraints/GroupSequence.php @@ -57,7 +57,7 @@ class GroupSequence /** * The groups in the sequence. * - * @var string[]|string[][]|GroupSequence[] + * @var array */ public $groups; @@ -80,7 +80,7 @@ class GroupSequence /** * Creates a new group sequence. * - * @param string[] $groups The groups in the sequence + * @param array $groups The groups in the sequence */ public function __construct(array $groups) {