[Form] Add parameter type declarations

This commit is contained in:
Valentin 2019-08-04 23:12:31 +03:00 committed by Nicolas Grekas
parent 3aca99ded7
commit 99a1d4cd26
50 changed files with 237 additions and 383 deletions

View File

@ -50,7 +50,7 @@ abstract class AbstractExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function getType($name)
public function getType(string $name)
{
if (null === $this->types) {
$this->initTypes();
@ -66,7 +66,7 @@ abstract class AbstractExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function hasType($name)
public function hasType(string $name)
{
if (null === $this->types) {
$this->initTypes();
@ -78,7 +78,7 @@ abstract class AbstractExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function getTypeExtensions($name)
public function getTypeExtensions(string $name)
{
if (null === $this->typeExtensions) {
$this->initTypeExtensions();
@ -92,7 +92,7 @@ abstract class AbstractExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function hasTypeExtensions($name)
public function hasTypeExtensions(string $name)
{
if (null === $this->typeExtensions) {
$this->initTypeExtensions();

View File

@ -123,7 +123,7 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
*
* @see getResourceForBlockHierarchy()
*/
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, $hierarchyLevel): bool
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, int $hierarchyLevel): bool
{
$blockName = $blockNameHierarchy[$hierarchyLevel];

View File

@ -128,7 +128,7 @@ class Button implements \IteratorAggregate, FormInterface
*
* @throws BadMethodCallException
*/
public function add($child, $type = null, array $options = [])
public function add($child, string $type = null, array $options = [])
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -138,11 +138,9 @@ class Button implements \IteratorAggregate, FormInterface
*
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException
*/
public function get($name)
public function get(string $name)
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -150,11 +148,9 @@ class Button implements \IteratorAggregate, FormInterface
/**
* Unsupported method.
*
* @param string $name
*
* @return bool Always returns false
*/
public function has($name)
public function has(string $name)
{
return false;
}
@ -164,11 +160,9 @@ class Button implements \IteratorAggregate, FormInterface
*
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException
*/
public function remove($name)
public function remove(string $name)
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -184,7 +178,7 @@ class Button implements \IteratorAggregate, FormInterface
/**
* {@inheritdoc}
*/
public function getErrors($deep = false, $flatten = true)
public function getErrors(bool $deep = false, bool $flatten = true)
{
return new FormErrorIterator($this, []);
}
@ -378,7 +372,7 @@ class Button implements \IteratorAggregate, FormInterface
*
* @throws Exception\AlreadySubmittedException if the button has already been submitted
*/
public function submit($submittedData, $clearMissing = true)
public function submit($submittedData, bool $clearMissing = true)
{
if ($this->submitted) {
throw new AlreadySubmittedException('A form can only be submitted once');

View File

@ -71,7 +71,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @throws BadMethodCallException
*/
public function add($child, $type = null, array $options = [])
public function add($child, string $type = null, array $options = [])
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -83,7 +83,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* @throws BadMethodCallException
*/
public function create($name, $type = null, array $options = [])
public function create(string $name, string $type = null, array $options = [])
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -93,11 +93,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException
*/
public function get($name)
public function get(string $name)
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -107,11 +105,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param string $name
*
* @throws BadMethodCallException
*/
public function remove($name)
public function remove(string $name)
{
throw new BadMethodCallException('Buttons cannot have children.');
}
@ -119,11 +115,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Unsupported method.
*
* @param string $name
*
* @return bool Always returns false
*/
public function has($name)
public function has(string $name)
{
return false;
}
@ -153,13 +147,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param string $eventName
* @param callable $listener
* @param int $priority
*
* @throws BadMethodCallException
*/
public function addEventListener($eventName, $listener, $priority = 0)
public function addEventListener(string $eventName, callable $listener, int $priority = 0)
{
throw new BadMethodCallException('Buttons do not support event listeners.');
}
@ -181,11 +171,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $forcePrepend
*
* @throws BadMethodCallException
*/
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false)
public function addViewTransformer(DataTransformerInterface $viewTransformer, bool $forcePrepend = false)
{
throw new BadMethodCallException('Buttons do not support data transformers.');
}
@ -207,11 +195,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $forceAppend
*
* @throws BadMethodCallException
*/
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false)
public function addModelTransformer(DataTransformerInterface $modelTransformer, bool $forceAppend = false)
{
throw new BadMethodCallException('Buttons do not support data transformers.');
}
@ -231,7 +217,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* {@inheritdoc}
*/
public function setAttribute($name, $value)
public function setAttribute(string $name, $value)
{
$this->attributes[$name] = $value;
@ -263,11 +249,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Set whether the button is disabled.
*
* @param bool $disabled Whether the button is disabled
*
* @return $this
*/
public function setDisabled($disabled)
public function setDisabled(bool $disabled)
{
$this->disabled = $disabled;
@ -293,11 +277,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $errorBubbling
*
* @throws BadMethodCallException
*/
public function setErrorBubbling($errorBubbling)
public function setErrorBubbling(bool $errorBubbling)
{
throw new BadMethodCallException('Buttons do not support error bubbling.');
}
@ -307,11 +289,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $required
*
* @throws BadMethodCallException
*/
public function setRequired($required)
public function setRequired(bool $required)
{
throw new BadMethodCallException('Buttons cannot be required.');
}
@ -335,11 +315,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $mapped
*
* @throws BadMethodCallException
*/
public function setMapped($mapped)
public function setMapped(bool $mapped)
{
throw new BadMethodCallException('Buttons do not support data mapping.');
}
@ -349,11 +327,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $byReference
*
* @throws BadMethodCallException
*/
public function setByReference($byReference)
public function setByReference(bool $byReference)
{
throw new BadMethodCallException('Buttons do not support data mapping.');
}
@ -363,11 +339,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $compound
*
* @throws BadMethodCallException
*/
public function setCompound($compound)
public function setCompound(bool $compound)
{
throw new BadMethodCallException('Buttons cannot be compound.');
}
@ -403,11 +377,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*
* This method should not be invoked.
*
* @param bool $locked
*
* @throws BadMethodCallException
*/
public function setDataLocked($locked)
public function setDataLocked(bool $locked)
{
throw new BadMethodCallException('Buttons do not support data locking.');
}
@ -427,11 +399,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Unsupported method.
*
* @param string $action
*
* @throws BadMethodCallException
*/
public function setAction($action)
public function setAction(string $action)
{
throw new BadMethodCallException('Buttons do not support actions.');
}
@ -439,11 +409,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Unsupported method.
*
* @param string $method
*
* @throws BadMethodCallException
*/
public function setMethod($method)
public function setMethod(string $method)
{
throw new BadMethodCallException('Buttons do not support methods.');
}
@ -461,13 +429,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Unsupported method.
*
* @param bool $initialize
*
* @return $this
*
* @throws BadMethodCallException
*/
public function setAutoInitialize($initialize)
public function setAutoInitialize(bool $initialize)
{
if (true === $initialize) {
throw new BadMethodCallException('Buttons do not support automatic initialization.');
@ -479,11 +445,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Unsupported method.
*
* @param bool $inheritData
*
* @throws BadMethodCallException
*/
public function setInheritData($inheritData)
public function setInheritData(bool $inheritData)
{
throw new BadMethodCallException('Buttons do not support data inheritance.');
}
@ -645,11 +609,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Returns whether the attribute with the given name exists.
*
* @param string $name The attribute name
*
* @return bool Whether the attribute exists
*/
public function hasAttribute($name)
public function hasAttribute(string $name)
{
return \array_key_exists($name, $this->attributes);
}
@ -657,12 +619,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Returns the value of the given attribute.
*
* @param string $name The attribute name
* @param mixed $default The value returned if the attribute does not exist
* @param mixed $default The value returned if the attribute does not exist
*
* @return mixed The attribute value
*/
public function getAttribute($name, $default = null)
public function getAttribute(string $name, $default = null)
{
return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
}
@ -758,11 +719,9 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Returns whether a specific option exists.
*
* @param string $name The option name,
*
* @return bool Whether the option exists
*/
public function hasOption($name)
public function hasOption(string $name)
{
return \array_key_exists($name, $this->options);
}
@ -770,12 +729,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
/**
* Returns the value of a specific option.
*
* @param string $name The option name
* @param mixed $default The value returned if the option does not exist
* @param mixed $default The value returned if the option does not exist
*
* @return mixed The option value
*/
public function getOption($name, $default = null)
public function getOption(string $name, $default = null)
{
return \array_key_exists($name, $this->options) ? $this->options[$name] : $default;
}

View File

@ -182,7 +182,7 @@ class ArrayChoiceList implements ChoiceListInterface
*
* @internal
*/
protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues)
protected function flatten(array $choices, callable $value, ?array &$choicesByValues, ?array &$keysByValues, ?array &$structuredValues)
{
if (null === $choicesByValues) {
$choicesByValues = [];

View File

@ -81,7 +81,7 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface, ResetInterf
/**
* {@inheritdoc}
*/
public function createListFromChoices($choices, $value = null)
public function createListFromChoices(iterable $choices, $value = null)
{
if ($choices instanceof \Traversable) {
$choices = iterator_to_array($choices);

View File

@ -31,12 +31,9 @@ interface ChoiceListFactoryInterface
* The callable receives the choice as only argument.
* Null may be passed when the choice list contains the empty value.
*
* @param iterable $choices The choices
* @param callable|null $value The callable generating the choice values
*
* @return ChoiceListInterface The choice list
*/
public function createListFromChoices($choices, $value = null);
public function createListFromChoices(iterable $choices, callable $value = null);
/**
* Creates a choice list that is loaded with the given loader.
@ -45,11 +42,9 @@ interface ChoiceListFactoryInterface
* The callable receives the choice as only argument.
* Null may be passed when the choice list contains the empty value.
*
* @param callable|null $value The callable generating the choice values
*
* @return ChoiceListInterface The choice list
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null);
public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value = null);
/**
* Creates a view for the given choice list.
@ -80,11 +75,9 @@ interface ChoiceListFactoryInterface
* @param array|callable|null $preferredChoices The preferred choices
* @param callable|false|null $label The callable generating the choice labels;
* pass false to discard the label
* @param callable|null $index The callable generating the view indices
* @param callable|null $groupBy The callable generating the group names
* @param array|callable|null $attr The callable generating the HTML attributes
*
* @return ChoiceListView The choice list view
*/
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null);
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, callable $index = null, callable $groupBy = null, $attr = null);
}

View File

@ -29,7 +29,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
/**
* {@inheritdoc}
*/
public function createListFromChoices($choices, $value = null)
public function createListFromChoices(iterable $choices, callable $value = null)
{
return new ArrayChoiceList($choices, $value);
}
@ -37,7 +37,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
/**
* {@inheritdoc}
*/
public function createListFromLoader(ChoiceLoaderInterface $loader, $value = null)
public function createListFromLoader(ChoiceLoaderInterface $loader, callable $value = null)
{
return new LazyChoiceList($loader, $value);
}
@ -45,7 +45,7 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
/**
* {@inheritdoc}
*/
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, $index = null, $groupBy = null, $attr = null)
public function createView(ChoiceListInterface $list, $preferredChoices = null, $label = null, callable $index = null, callable $groupBy = null, $attr = null)
{
$preferredViews = [];
$preferredViewsOrder = [];

View File

@ -59,13 +59,12 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
/**
* {@inheritdoc}
*
* @param iterable $choices The choices
* @param callable|string|PropertyPath|null $value The callable or path for
* generating the choice values
* @param callable|string|PropertyPath|null $value The callable or path for
* generating the choice values
*
* @return ChoiceListInterface The choice list
*/
public function createListFromChoices($choices, $value = null)
public function createListFromChoices(iterable $choices, $value = null)
{
if (\is_string($value)) {
$value = new PropertyPath($value);

View File

@ -40,7 +40,7 @@ class CallbackChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadChoiceList($value = null)
public function loadChoiceList(callable $value = null)
{
if (null !== $this->choiceList) {
return $this->choiceList;
@ -52,7 +52,7 @@ class CallbackChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
public function loadChoicesForValues(array $values, callable $value = null)
{
// Optimize
if (empty($values)) {
@ -65,7 +65,7 @@ class CallbackChoiceLoader implements ChoiceLoaderInterface
/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, $value = null)
public function loadValuesForChoices(array $choices, callable $value = null)
{
// Optimize
if (empty($choices)) {

View File

@ -22,7 +22,7 @@ class IntlCallbackChoiceLoader extends CallbackChoiceLoader
/**
* {@inheritdoc}
*/
public function loadChoicesForValues(array $values, $value = null)
public function loadChoicesForValues(array $values, callable $value = null)
{
// Optimize
$values = array_filter($values);
@ -36,7 +36,7 @@ class IntlCallbackChoiceLoader extends CallbackChoiceLoader
/**
* {@inheritdoc}
*/
public function loadValuesForChoices(array $choices, $value = null)
public function loadValuesForChoices(array $choices, callable $value = null)
{
// Optimize
$choices = array_filter($choices);

View File

@ -24,10 +24,9 @@ class ChoiceGroupView implements \IteratorAggregate
/**
* Creates a new choice group view.
*
* @param string $label The label of the group
* @param ChoiceGroupView[]|ChoiceView[] $choices the choice views in the group
*/
public function __construct($label, array $choices = [])
public function __construct(string $label, array $choices = [])
{
$this->label = $label;
$this->choices = $choices;

View File

@ -106,7 +106,7 @@ abstract class Descriptor implements DescriptorInterface
$this->extensions = array_keys($this->extensions);
}
protected function getOptionDefinition(OptionsResolver $optionsResolver, $option)
protected function getOptionDefinition(OptionsResolver $optionsResolver, string $option)
{
$definition = [
'required' => $optionsResolver->isRequired($option),

View File

@ -22,12 +22,12 @@ interface DataMapperInterface
* The method is responsible for calling {@link FormInterface::setData()}
* on the children of compound forms, defining their underlying model data.
*
* @param mixed $viewData View data of the compound form being initialized
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
* @param mixed $viewData View data of the compound form being initialized
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
*/
public function mapDataToForms($viewData, $forms);
public function mapDataToForms($viewData, iterable $forms);
/**
* Maps the model data of a list of children forms into the view data of their parent.
@ -52,11 +52,11 @@ interface DataMapperInterface
* The model data can be an array or an object, so this second argument is always passed
* by reference.
*
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
* @param mixed $viewData The compound form's view data that get mapped
* its children model data
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
* @param mixed $viewData The compound form's view data that get mapped
* its children model data
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
*/
public function mapFormsToData($forms, &$viewData);
public function mapFormsToData(iterable $forms, &$viewData);
}

View File

@ -28,7 +28,7 @@ class CheckboxListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapDataToForms($choices, $checkboxes)
public function mapDataToForms($choices, iterable $checkboxes)
{
if (null === $choices) {
$choices = [];
@ -47,7 +47,7 @@ class CheckboxListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapFormsToData($checkboxes, &$choices)
public function mapFormsToData(iterable $checkboxes, &$choices)
{
if (!\is_array($choices)) {
throw new UnexpectedTypeException($choices, 'array');

View File

@ -33,7 +33,7 @@ class PropertyPathMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapDataToForms($data, $forms)
public function mapDataToForms($data, iterable $forms)
{
$empty = null === $data || [] === $data;
@ -56,7 +56,7 @@ class PropertyPathMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapFormsToData($forms, &$data)
public function mapFormsToData(iterable $forms, &$data)
{
if (null === $data) {
return;

View File

@ -28,7 +28,7 @@ class RadioListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapDataToForms($choice, $radios)
public function mapDataToForms($choice, iterable $radios)
{
if (!\is_string($choice)) {
throw new UnexpectedTypeException($choice, 'string');
@ -43,7 +43,7 @@ class RadioListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapFormsToData($radios, &$choice)
public function mapFormsToData(iterable $radios, &$choice)
{
if (null !== $choice && !\is_string($choice)) {
throw new UnexpectedTypeException($choice, 'null or string');

View File

@ -69,7 +69,7 @@ class ResolvedTypeDataCollectorProxy implements ResolvedFormTypeInterface
/**
* {@inheritdoc}
*/
public function createBuilder(FormFactoryInterface $factory, $name, array $options = [])
public function createBuilder(FormFactoryInterface $factory, string $name, array $options = [])
{
$builder = $this->proxiedType->createBuilder($factory, $name, $options);

View File

@ -35,7 +35,10 @@ class DependencyInjectionExtension implements FormExtensionInterface
$this->guesserServices = $guesserServices;
}
public function getType($name)
/**
* {@inheritdoc}
*/
public function getType(string $name)
{
if (!$this->typeContainer->has($name)) {
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered in the service container.', $name));
@ -44,12 +47,18 @@ class DependencyInjectionExtension implements FormExtensionInterface
return $this->typeContainer->get($name);
}
public function hasType($name)
/**
* {@inheritdoc}
*/
public function hasType(string $name)
{
return $this->typeContainer->has($name);
}
public function getTypeExtensions($name)
/**
* {@inheritdoc}
*/
public function getTypeExtensions(string $name)
{
$extensions = [];
@ -72,11 +81,17 @@ class DependencyInjectionExtension implements FormExtensionInterface
return $extensions;
}
public function hasTypeExtensions($name)
/**
* {@inheritdoc}
*/
public function hasTypeExtensions(string $name)
{
return isset($this->typeExtensionServices[$name]);
}
/**
* {@inheritdoc}
*/
public function getTypeGuesser()
{
if (!$this->guesserLoaded) {

View File

@ -31,7 +31,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessType($class, $property)
public function guessType(string $class, string $property)
{
return $this->guess($class, $property, function (Constraint $constraint) {
return $this->guessTypeForConstraint($constraint);
@ -41,7 +41,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessRequired($class, $property)
public function guessRequired(string $class, string $property)
{
return $this->guess($class, $property, function (Constraint $constraint) {
return $this->guessRequiredForConstraint($constraint);
@ -53,7 +53,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessMaxLength($class, $property)
public function guessMaxLength(string $class, string $property)
{
return $this->guess($class, $property, function (Constraint $constraint) {
return $this->guessMaxLengthForConstraint($constraint);
@ -63,7 +63,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessPattern($class, $property)
public function guessPattern(string $class, string $property)
{
return $this->guess($class, $property, function (Constraint $constraint) {
return $this->guessPatternForConstraint($constraint);
@ -243,8 +243,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
* Iterates over the constraints of a property, executes a constraints on
* them and returns the best guess.
*
* @param string $class The class to read the constraints from
* @param string $property The property for which to find constraints
* @param \Closure $closure The closure that returns a guess
* for a given constraint
* @param mixed $defaultValue The default value assumed if no other value
@ -252,7 +250,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
*
* @return Guess|null The guessed value with the highest confidence
*/
protected function guess($class, $property, \Closure $closure, $defaultValue = null)
protected function guess(string $class, string $property, \Closure $closure, $defaultValue = null)
{
$guesses = [];
$classMetadata = $this->metadataFactory->getMetadataFor($class);

View File

@ -44,11 +44,9 @@ class MappingRule
* If the rule matches, the form mapped by the rule is returned.
* Otherwise this method returns false.
*
* @param string $propertyPath The property path to match against the rule
*
* @return FormInterface|null The mapped form or null
*/
public function match($propertyPath)
public function match(string $propertyPath)
{
if ($propertyPath === $this->propertyPath) {
return $this->getTarget();
@ -58,11 +56,9 @@ class MappingRule
/**
* Matches a property path against a prefix of the rule path.
*
* @param string $propertyPath The property path to match against the rule
*
* @return bool Whether the property path is a prefix of the rule or not
*/
public function isPrefix($propertyPath)
public function isPrefix(string $propertyPath)
{
$length = \strlen($propertyPath);
$prefix = substr($this->propertyPath, 0, $length);

View File

@ -32,7 +32,7 @@ class ViolationMapper implements ViolationMapperInterface
/**
* {@inheritdoc}
*/
public function mapViolation(ConstraintViolation $violation, FormInterface $form, $allowNonSynchronized = false)
public function mapViolation(ConstraintViolation $violation, FormInterface $form, bool $allowNonSynchronized = false)
{
$this->allowNonSynchronized = $allowNonSynchronized;

View File

@ -25,5 +25,5 @@ interface ViolationMapperInterface
*
* @param bool $allowNonSynchronized Whether to allow mapping to non-synchronized forms
*/
public function mapViolation(ConstraintViolation $violation, FormInterface $form, $allowNonSynchronized = false);
public function mapViolation(ConstraintViolation $violation, FormInterface $form, bool $allowNonSynchronized = false);
}

View File

@ -160,7 +160,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
/**
* {@inheritdoc}
*/
public function getElement($index)
public function getElement(int $index)
{
if (!isset($this->elements[$index])) {
throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
@ -172,7 +172,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
/**
* {@inheritdoc}
*/
public function isProperty($index)
public function isProperty(int $index)
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
@ -184,7 +184,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
/**
* {@inheritdoc}
*/
public function isIndex($index)
public function isIndex(int $index)
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
@ -203,13 +203,11 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
* In this example, "address" and "office" map to forms, while
* "street does not.
*
* @param int $index The element index
*
* @return bool Whether the element maps to a form
*
* @throws OutOfBoundsException if the offset is invalid
*/
public function mapsForm($index)
public function mapsForm(int $index)
{
if (!isset($this->mapsForm[$index])) {
throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));

View File

@ -497,7 +497,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function submit($submittedData, $clearMissing = true)
public function submit($submittedData, bool $clearMissing = true)
{
if ($this->submitted) {
throw new AlreadySubmittedException('A form can only be submitted once');
@ -768,7 +768,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function getErrors($deep = false, $flatten = true)
public function getErrors(bool $deep = false, bool $flatten = true)
{
$errors = $this->errors;
@ -831,7 +831,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function add($child, $type = null, array $options = [])
public function add($child, string $type = null, array $options = [])
{
if ($this->submitted) {
throw new AlreadySubmittedException('You cannot add children to a submitted form');
@ -902,7 +902,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function remove($name)
public function remove(string $name)
{
if ($this->submitted) {
throw new AlreadySubmittedException('You cannot remove children from a submitted form');
@ -922,7 +922,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return isset($this->children[$name]);
}
@ -930,7 +930,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
if (isset($this->children[$name])) {
return $this->children[$name];

View File

@ -47,7 +47,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
/**
* {@inheritdoc}
*/
public function add($child, $type = null, array $options = [])
public function add($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 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
/**
* {@inheritdoc}
*/
public function create($name, $type = null, array $options = [])
public function create($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.');

View File

@ -24,11 +24,10 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
* object hierarchy.
*
* @param string|FormBuilderInterface $child
* @param string|null $type
*
* @return self
*/
public function add($child, $type = null, array $options = []);
public function add($child, string $type = null, array $options = []);
/**
* Creates a form builder.
@ -38,36 +37,30 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
*
* @return self
*/
public function create($name, $type = null, array $options = []);
public function create(string $name, string $type = null, array $options = []);
/**
* Returns a child by name.
*
* @param string $name The name of the child
*
* @return self
*
* @throws Exception\InvalidArgumentException if the given child does not exist
*/
public function get($name);
public function get(string $name);
/**
* Removes the field with the given name.
*
* @param string $name
*
* @return self
*/
public function remove($name);
public function remove(string $name);
/**
* Returns whether a field with the given name exists.
*
* @param string $name
*
* @return bool
*/
public function has($name);
public function has(string $name);
/**
* Returns the children.

View File

@ -129,7 +129,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function addEventListener($eventName, $listener, $priority = 0)
public function addEventListener(string $eventName, callable $listener, int $priority = 0)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
@ -157,7 +157,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false)
public function addViewTransformer(DataTransformerInterface $viewTransformer, bool $forcePrepend = false)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
@ -189,7 +189,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false)
public function addModelTransformer(DataTransformerInterface $modelTransformer, bool $forceAppend = false)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
@ -353,7 +353,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function hasAttribute($name)
public function hasAttribute(string $name)
{
return \array_key_exists($name, $this->attributes);
}
@ -361,7 +361,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function getAttribute($name, $default = null)
public function getAttribute(string $name, $default = null)
{
return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
}
@ -448,7 +448,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function hasOption($name)
public function hasOption(string $name)
{
return \array_key_exists($name, $this->options);
}
@ -456,7 +456,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function getOption($name, $default = null)
public function getOption(string $name, $default = null)
{
return \array_key_exists($name, $this->options) ? $this->options[$name] : $default;
}
@ -464,7 +464,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setAttribute($name, $value)
public function setAttribute(string $name, $value)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
@ -506,13 +506,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setDisabled($disabled)
public function setDisabled(bool $disabled)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->disabled = (bool) $disabled;
$this->disabled = $disabled;
return $this;
}
@ -534,13 +534,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setErrorBubbling($errorBubbling)
public function setErrorBubbling(bool $errorBubbling)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->errorBubbling = (bool) $errorBubbling;
$this->errorBubbling = $errorBubbling;
return $this;
}
@ -548,13 +548,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setRequired($required)
public function setRequired(bool $required)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->required = (bool) $required;
$this->required = $required;
return $this;
}
@ -580,13 +580,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setMapped($mapped)
public function setMapped(bool $mapped)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->mapped = (bool) $mapped;
$this->mapped = $mapped;
return $this;
}
@ -594,13 +594,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setByReference($byReference)
public function setByReference(bool $byReference)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->byReference = (bool) $byReference;
$this->byReference = $byReference;
return $this;
}
@ -608,13 +608,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setInheritData($inheritData)
public function setInheritData(bool $inheritData)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->inheritData = (bool) $inheritData;
$this->inheritData = $inheritData;
return $this;
}
@ -622,13 +622,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setCompound($compound)
public function setCompound(bool $compound)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->compound = (bool) $compound;
$this->compound = $compound;
return $this;
}
@ -664,13 +664,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setDataLocked($locked)
public function setDataLocked(bool $locked)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->dataLocked = (bool) $locked;
$this->dataLocked = $locked;
return $this;
}
@ -692,13 +692,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setAction($action)
public function setAction(string $action)
{
if ($this->locked) {
throw new BadMethodCallException('The config builder cannot be modified anymore.');
}
$this->action = (string) $action;
$this->action = $action;
return $this;
}
@ -706,7 +706,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setMethod($method)
public function setMethod(string $method)
{
if ($this->locked) {
throw new BadMethodCallException('The config builder cannot be modified anymore.');
@ -734,13 +734,13 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* {@inheritdoc}
*/
public function setAutoInitialize($initialize)
public function setAutoInitialize(bool $initialize)
{
if ($this->locked) {
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
$this->autoInitialize = (bool) $initialize;
$this->autoInitialize = $initialize;
return $this;
}

View File

@ -22,15 +22,13 @@ interface FormConfigBuilderInterface extends FormConfigInterface
/**
* Adds an event listener to an event on this form.
*
* @param string $eventName The name of the event to listen to
* @param callable $listener The listener to execute
* @param int $priority The priority of the listener. Listeners
* with a higher priority are called before
* listeners with a lower priority.
* @param int $priority The priority of the listener. Listeners
* with a higher priority are called before
* listeners with a lower priority.
*
* @return $this The configuration object
*/
public function addEventListener($eventName, $listener, $priority = 0);
public function addEventListener(string $eventName, callable $listener, int $priority = 0);
/**
* Adds an event subscriber for events on this form.
@ -51,7 +49,7 @@ interface FormConfigBuilderInterface extends FormConfigInterface
*
* @return $this The configuration object
*/
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false);
public function addViewTransformer(DataTransformerInterface $viewTransformer, bool $forcePrepend = false);
/**
* Clears the view transformers.
@ -72,7 +70,7 @@ interface FormConfigBuilderInterface extends FormConfigInterface
*
* @return $this The configuration object
*/
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false);
public function addModelTransformer(DataTransformerInterface $modelTransformer, bool $forceAppend = false);
/**
* Clears the normalization transformers.
@ -84,12 +82,11 @@ interface FormConfigBuilderInterface extends FormConfigInterface
/**
* Sets the value for an attribute.
*
* @param string $name The name of the attribute
* @param mixed $value The value of the attribute
* @param mixed $value The value of the attribute
*
* @return $this The configuration object
*/
public function setAttribute($name, $value);
public function setAttribute(string $name, $value);
/**
* Sets the attributes.
@ -108,11 +105,9 @@ interface FormConfigBuilderInterface extends FormConfigInterface
/**
* Sets whether the form is disabled.
*
* @param bool $disabled Whether the form is disabled
*
* @return $this The configuration object
*/
public function setDisabled($disabled);
public function setDisabled(bool $disabled);
/**
* Sets the data used for the client data when no value is submitted.
@ -126,20 +121,16 @@ interface FormConfigBuilderInterface extends FormConfigInterface
/**
* Sets whether errors bubble up to the parent.
*
* @param bool $errorBubbling
*
* @return $this The configuration object
*/
public function setErrorBubbling($errorBubbling);
public function setErrorBubbling(bool $errorBubbling);
/**
* Sets whether this field is required to be filled out when submitted.
*
* @param bool $required
*
* @return $this The configuration object
*/
public function setRequired($required);
public function setRequired(bool $required);
/**
* Sets the property path that the form should be mapped to.
@ -155,40 +146,32 @@ interface FormConfigBuilderInterface extends FormConfigInterface
* Sets whether the form should be mapped to an element of its
* parent's data.
*
* @param bool $mapped Whether the form should be mapped
*
* @return $this The configuration object
*/
public function setMapped($mapped);
public function setMapped(bool $mapped);
/**
* Sets whether the form's data should be modified by reference.
*
* @param bool $byReference Whether the data should be modified by reference
*
* @return $this The configuration object
*/
public function setByReference($byReference);
public function setByReference(bool $byReference);
/**
* Sets whether the form should read and write the data of its parent.
*
* @param bool $inheritData Whether the form should inherit its parent's data
*
* @return $this The configuration object
*/
public function setInheritData($inheritData);
public function setInheritData(bool $inheritData);
/**
* Sets whether the form should be compound.
*
* @param bool $compound Whether the form should be compound
*
* @return $this The configuration object
*
* @see FormConfigInterface::getCompound()
*/
public function setCompound($compound);
public function setCompound(bool $compound);
/**
* Sets the resolved type.
@ -216,11 +199,9 @@ interface FormConfigBuilderInterface extends FormConfigInterface
* It means data passed to a factory method or mapped from the
* parent will be ignored.
*
* @param bool $locked Whether to lock the default configured data
*
* @return $this The configuration object
*/
public function setDataLocked($locked);
public function setDataLocked(bool $locked);
/**
* Sets the form factory used for creating new forms.
@ -230,20 +211,16 @@ interface FormConfigBuilderInterface extends FormConfigInterface
/**
* Sets the target URL of the form.
*
* @param string $action The target URL of the form
*
* @return $this The configuration object
*/
public function setAction($action);
public function setAction(string $action);
/**
* Sets the HTTP method used by the form.
*
* @param string $method The HTTP method of the form
*
* @return $this The configuration object
*/
public function setMethod($method);
public function setMethod(string $method);
/**
* Sets the request handler used by the form.
@ -264,7 +241,7 @@ interface FormConfigBuilderInterface extends FormConfigInterface
*
* @return $this The configuration object
*/
public function setAutoInitialize($initialize);
public function setAutoInitialize(bool $initialize);
/**
* Builds and returns the form configuration.

View File

@ -149,21 +149,18 @@ interface FormConfigInterface
/**
* Returns whether the attribute with the given name exists.
*
* @param string $name The attribute name
*
* @return bool Whether the attribute exists
*/
public function hasAttribute($name);
public function hasAttribute(string $name);
/**
* Returns the value of the given attribute.
*
* @param string $name The attribute name
* @param mixed $default The value returned if the attribute does not exist
* @param mixed $default The value returned if the attribute does not exist
*
* @return mixed The attribute value
*/
public function getAttribute($name, $default = null);
public function getAttribute(string $name, $default = null);
/**
* Returns the initial data of the form.
@ -236,19 +233,16 @@ interface FormConfigInterface
/**
* Returns whether a specific option exists.
*
* @param string $name The option name,
*
* @return bool Whether the option exists
*/
public function hasOption($name);
public function hasOption(string $name);
/**
* Returns the value of a specific option.
*
* @param string $name The option name
* @param mixed $default The value returned if the option does not exist
* @param mixed $default The value returned if the option does not exist
*
* @return mixed The option value
*/
public function getOption($name, $default = null);
public function getOption(string $name, $default = null);
}

View File

@ -25,7 +25,7 @@ interface FormExtensionInterface
*
* @throws Exception\InvalidArgumentException if the given type is not supported by this extension
*/
public function getType($name);
public function getType(string $name);
/**
* Returns whether the given type is supported.
@ -34,7 +34,7 @@ interface FormExtensionInterface
*
* @return bool Whether the type is supported by this extension
*/
public function hasType($name);
public function hasType(string $name);
/**
* Returns the extensions for the given type.
@ -43,7 +43,7 @@ interface FormExtensionInterface
*
* @return FormTypeExtensionInterface[] An array of extensions as FormTypeExtensionInterface instances
*/
public function getTypeExtensions($name);
public function getTypeExtensions(string $name);
/**
* Returns whether this extension provides type extensions for the given type.
@ -52,7 +52,7 @@ interface FormExtensionInterface
*
* @return bool Whether the given type has extensions
*/
public function hasTypeExtensions($name);
public function hasTypeExtensions(string $name);
/**
* Returns the type guesser provided by this extension.

View File

@ -11,8 +11,6 @@
namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
class FormFactory implements FormFactoryInterface
{
private $registry;
@ -25,7 +23,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
public function create($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
public function create(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
{
return $this->createBuilder($type, $data, $options)->getForm();
}
@ -33,7 +31,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
public function createNamed(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
{
return $this->createNamedBuilder($name, $type, $data, $options)->getForm();
}
@ -41,7 +39,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
public function createForProperty($class, $property, $data = null, array $options = [])
public function createForProperty(string $class, string $property, $data = null, array $options = [])
{
return $this->createBuilderForProperty($class, $property, $data, $options)->getForm();
}
@ -49,28 +47,20 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
public function createBuilder(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
{
if (!\is_string($type)) {
throw new UnexpectedTypeException($type, 'string');
}
return $this->createNamedBuilder($this->registry->getType($type)->getBlockPrefix(), $type, $data, $options);
}
/**
* {@inheritdoc}
*/
public function createNamedBuilder($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
public function createNamedBuilder(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
{
if (null !== $data && !\array_key_exists('data', $options)) {
$options['data'] = $data;
}
if (!\is_string($type)) {
throw new UnexpectedTypeException($type, 'string');
}
$type = $this->registry->getType($type);
$builder = $type->createBuilder($this, (string) $name, $options);
@ -85,7 +75,7 @@ class FormFactory implements FormFactoryInterface
/**
* {@inheritdoc}
*/
public function createBuilderForProperty($class, $property, $data = null, array $options = [])
public function createBuilderForProperty(string $class, string $property, $data = null, array $options = [])
{
if (null === $guesser = $this->registry->getTypeGuesser()) {
return $this->createNamedBuilder($property, 'Symfony\Component\Form\Extension\Core\Type\TextType', $data, $options);

View File

@ -23,29 +23,26 @@ interface FormFactoryInterface
*
* @see createBuilder()
*
* @param string $type The type of the form
* @param mixed $data The initial data
* @param mixed $data The initial data
*
* @return FormInterface The form named after the type
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
*/
public function create($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
public function create(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
/**
* Returns a form.
*
* @see createNamedBuilder()
*
* @param string $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
* @param mixed $data The initial data
*
* @return FormInterface The form
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
*/
public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
public function createNamed(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
/**
* Returns a form for a property of a class.
@ -60,32 +57,30 @@ interface FormFactoryInterface
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type
*/
public function createForProperty($class, $property, $data = null, array $options = []);
public function createForProperty(string $class, string $property, $data = null, array $options = []);
/**
* Returns a form builder.
*
* @param string $type The type of the form
* @param mixed $data The initial data
* @param mixed $data The initial data
*
* @return FormBuilderInterface The form builder
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
*/
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
public function createBuilder(string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
/**
* Returns a form builder.
*
* @param string $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
* @param mixed $data The initial data
*
* @return FormBuilderInterface The form builder
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
*/
public function createNamedBuilder($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
public function createNamedBuilder(string $name, string $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
/**
* Returns a form builder for a property of a class.
@ -101,5 +96,5 @@ interface FormFactoryInterface
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type
*/
public function createBuilderForProperty($class, $property, $data = null, array $options = []);
public function createBuilderForProperty(string $class, string $property, $data = null, array $options = []);
}

View File

@ -53,38 +53,32 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @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, $type = null, array $options = []);
public function add($child, string $type = null, array $options = []);
/**
* Returns the child with the given name.
*
* @param string $name The name of the child
*
* @return self
*
* @throws \OutOfBoundsException if the named child does not exist
*/
public function get($name);
public function get(string $name);
/**
* Returns whether a child with the given name exists.
*
* @param string $name The name of the child
*
* @return bool
*/
public function has($name);
public function has(string $name);
/**
* Removes a child from the form.
*
* @param string $name The name of the child to remove
*
* @return $this
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
*/
public function remove($name);
public function remove(string $name);
/**
* Returns all children in this group.
@ -103,7 +97,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @return FormErrorIterator An iterator over the {@link FormError}
* instances that where added to this form
*/
public function getErrors($deep = false, $flatten = true);
public function getErrors(bool $deep = false, bool $flatten = true);
/**
* Updates the form with default model data.
@ -309,7 +303,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
*/
public function submit($submittedData, $clearMissing = true);
public function submit($submittedData, bool $clearMissing = true);
/**
* Returns the root of the form tree.

View File

@ -67,7 +67,7 @@ class FormRegistry implements FormRegistryInterface
/**
* {@inheritdoc}
*/
public function getType($name)
public function getType(string $name)
{
if (!isset($this->types[$name])) {
$type = null;
@ -134,7 +134,7 @@ class FormRegistry implements FormRegistryInterface
/**
* {@inheritdoc}
*/
public function hasType($name)
public function hasType(string $name)
{
if (isset($this->types[$name])) {
return true;

View File

@ -23,22 +23,18 @@ interface FormRegistryInterface
*
* This methods registers the type extensions from the form extensions.
*
* @param string $name The name of the type
*
* @return ResolvedFormTypeInterface The type
*
* @throws Exception\InvalidArgumentException if the type can not be retrieved from any extension
*/
public function getType($name);
public function getType(string $name);
/**
* Returns whether the given form type is supported.
*
* @param string $name The name of the type
*
* @return bool Whether the type is supported
*/
public function hasType($name);
public function hasType(string $name);
/**
* Returns the guesser responsible for guessing types.

View File

@ -48,7 +48,7 @@ class FormRenderer implements FormRendererInterface
/**
* {@inheritdoc}
*/
public function setTheme(FormView $view, $themes, $useDefaultThemes = true)
public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true)
{
$this->engine->setTheme($view, $themes, $useDefaultThemes);
}
@ -56,7 +56,7 @@ class FormRenderer implements FormRendererInterface
/**
* {@inheritdoc}
*/
public function renderCsrfToken($tokenId)
public function renderCsrfToken(string $tokenId)
{
if (null === $this->csrfTokenManager) {
throw new BadMethodCallException('CSRF tokens can only be generated if a CsrfTokenManagerInterface is injected in FormRenderer::__construct().');
@ -68,7 +68,7 @@ class FormRenderer implements FormRendererInterface
/**
* {@inheritdoc}
*/
public function renderBlock(FormView $view, $blockName, array $variables = [])
public function renderBlock(FormView $view, string $blockName, array $variables = [])
{
$resource = $this->engine->getResourceForBlockName($view, $blockName);
@ -127,7 +127,7 @@ class FormRenderer implements FormRendererInterface
/**
* {@inheritdoc}
*/
public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = [])
public function searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = [])
{
$renderOnlyOnce = 'row' === $blockNameSuffix || 'widget' === $blockNameSuffix;
@ -280,7 +280,7 @@ class FormRenderer implements FormRendererInterface
/**
* {@inheritdoc}
*/
public function humanize($text)
public function humanize(string $text)
{
return ucfirst(strtolower(trim(preg_replace(['/([A-Z])/', '/[_\s]+/'], ['_$1', ' '], $text))));
}
@ -288,7 +288,7 @@ class FormRenderer implements FormRendererInterface
/**
* @internal
*/
public function encodeCurrency(Environment $environment, $text, $widget = '')
public function encodeCurrency(Environment $environment, string $text, string $widget = '')
{
if ('UTF-8' === $charset = $environment->getCharset()) {
$text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

View File

@ -128,7 +128,6 @@ interface FormRendererEngineInterface
*
* @param FormView $view The view to render
* @param mixed $resource The renderer resource
* @param string $blockName The name of the block to render
* @param array $variables The variables to pass to the template
*
* @return string The HTML markup

View File

@ -34,18 +34,17 @@ interface FormRendererInterface
* @param bool $useDefaultThemes If true, will use default themes specified
* in the renderer
*/
public function setTheme(FormView $view, $themes, $useDefaultThemes = true);
public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true);
/**
* Renders a named block of the form theme.
*
* @param FormView $view The view for which to render the block
* @param string $blockName The name of the block
* @param array $variables The variables to pass to the template
*
* @return string The HTML markup
*/
public function renderBlock(FormView $view, $blockName, array $variables = []);
public function renderBlock(FormView $view, string $blockName, array $variables = []);
/**
* Searches and renders a block for a given name suffix.
@ -57,13 +56,12 @@ interface FormRendererInterface
* If this method is called recursively, the block search is continued
* where a block was found before.
*
* @param FormView $view The view for which to render the block
* @param string $blockNameSuffix The suffix of the block name
* @param array $variables The variables to pass to the template
* @param FormView $view The view for which to render the block
* @param array $variables The variables to pass to the template
*
* @return string The HTML markup
*/
public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = []);
public function searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = []);
/**
* Renders a CSRF token.
@ -80,11 +78,9 @@ interface FormRendererInterface
* throw new \RuntimeException('CSRF attack detected.');
* }
*
* @param string $tokenId The ID of the CSRF token
*
* @return string A CSRF token
*/
public function renderCsrfToken($tokenId);
public function renderCsrfToken(string $tokenId);
/**
* Makes a technical name human readable.
@ -93,9 +89,7 @@ interface FormRendererInterface
* of the resulting string is capitalized, while all other letters are
* turned to lowercase.
*
* @param string $text The text to humanize
*
* @return string The humanized text
*/
public function humanize($text);
public function humanize(string $text);
}

View File

@ -41,7 +41,7 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessType($class, $property)
public function guessType(string $class, string $property)
{
return $this->guess(function ($guesser) use ($class, $property) {
return $guesser->guessType($class, $property);
@ -51,7 +51,7 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessRequired($class, $property)
public function guessRequired(string $class, string $property)
{
return $this->guess(function ($guesser) use ($class, $property) {
return $guesser->guessRequired($class, $property);
@ -61,7 +61,7 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessMaxLength($class, $property)
public function guessMaxLength(string $class, string $property)
{
return $this->guess(function ($guesser) use ($class, $property) {
return $guesser->guessMaxLength($class, $property);
@ -71,7 +71,7 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
/**
* {@inheritdoc}
*/
public function guessPattern($class, $property)
public function guessPattern(string $class, string $property)
{
return $this->guess(function ($guesser) use ($class, $property) {
return $guesser->guessPattern($class, $property);

View File

@ -43,7 +43,7 @@ class PreloadedExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function getType($name)
public function getType(string $name)
{
if (!isset($this->types[$name])) {
throw new InvalidArgumentException(sprintf('The type "%s" can not be loaded by this extension', $name));
@ -55,7 +55,7 @@ class PreloadedExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function hasType($name)
public function hasType(string $name)
{
return isset($this->types[$name]);
}
@ -63,7 +63,7 @@ class PreloadedExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function getTypeExtensions($name)
public function getTypeExtensions(string $name)
{
return isset($this->typeExtensions[$name])
? $this->typeExtensions[$name]
@ -73,7 +73,7 @@ class PreloadedExtension implements FormExtensionInterface
/**
* {@inheritdoc}
*/
public function hasTypeExtensions($name)
public function hasTypeExtensions(string $name)
{
return !empty($this->typeExtensions[$name]);
}

View File

@ -91,7 +91,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
/**
* {@inheritdoc}
*/
public function createBuilder(FormFactoryInterface $factory, $name, array $options = [])
public function createBuilder(FormFactoryInterface $factory, string $name, array $options = [])
{
try {
$options = $this->getOptionsResolver()->resolve($options);
@ -198,12 +198,9 @@ class ResolvedFormType implements ResolvedFormTypeInterface
*
* Override this method if you want to customize the builder class.
*
* @param string $name The name of the builder
* @param string|null $dataClass The data class
*
* @return FormBuilderInterface The new builder instance
*/
protected function newBuilder($name, $dataClass, FormFactoryInterface $factory, array $options)
protected function newBuilder(string $name, ?string $dataClass, FormFactoryInterface $factory, array $options)
{
if ($this->innerType instanceof ButtonTypeInterface) {
return new ButtonBuilder($name, $options);

View File

@ -55,7 +55,7 @@ interface ResolvedFormTypeInterface
*
* @return FormBuilderInterface The created form builder
*/
public function createBuilder(FormFactoryInterface $factory, $name, array $options = []);
public function createBuilder(FormFactoryInterface $factory, string $name, array $options = []);
/**
* Creates a new form view for a form of this type.

View File

@ -18,9 +18,6 @@ namespace Symfony\Component\Form;
*/
class SubmitButton extends Button implements ClickableInterface
{
/**
* @var bool
*/
private $clicked = false;
/**
@ -41,7 +38,7 @@ class SubmitButton extends Button implements ClickableInterface
*
* @throws Exception\AlreadySubmittedException if the form has already been submitted
*/
public function submit($submittedData, $clearMissing = true)
public function submit($submittedData, bool $clearMissing = true)
{
if ($this->getConfig()->getDisabled()) {
$this->clicked = false;

View File

@ -45,17 +45,15 @@ abstract class FormPerformanceTestCase extends FormIntegrationTestCase
}
/**
* @param int $maxRunningTime
*
* @throws \InvalidArgumentException
*/
public function setMaxRunningTime($maxRunningTime)
public function setMaxRunningTime(int $maxRunningTime)
{
if (\is_int($maxRunningTime) && $maxRunningTime >= 0) {
$this->maxRunningTime = $maxRunningTime;
} else {
if ($maxRunningTime < 0) {
throw new \InvalidArgumentException();
}
$this->maxRunningTime = $maxRunningTime;
}
/**

View File

@ -55,12 +55,6 @@ class FormBuilderTest extends TestCase
$this->builder->add(true);
}
public function testAddTypeNoString()
{
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->builder->add('foo', 1234);
}
public function testAddWithGuessFluent()
{
$this->builder = new FormBuilder('name', 'stdClass', $this->dispatcher, $this->factory);

View File

@ -147,20 +147,6 @@ class FormFactoryTest extends TestCase
$this->assertSame($this->builder, $this->factory->createNamedBuilder('name', 'type', 'DATA', $options));
}
public function testCreateNamedBuilderThrowsUnderstandableException()
{
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->expectExceptionMessage('Expected argument of type "string", "stdClass" given');
$this->factory->createNamedBuilder('name', new \stdClass());
}
public function testCreateThrowsUnderstandableException()
{
$this->expectException('Symfony\Component\Form\Exception\UnexpectedTypeException');
$this->expectExceptionMessage('Expected argument of type "string", "stdClass" given');
$this->factory->create(new \stdClass());
}
public function testCreateUsesBlockPrefixIfTypeGivenAsString()
{
$options = ['a' => '1', 'b' => '2'];

View File

@ -24,7 +24,7 @@ class OptionsResolverWrapper extends OptionsResolver
{
private $undefined = [];
public function setNormalizer($option, \Closure $normalizer)
public function setNormalizer(string $option, \Closure $normalizer)
{
try {
parent::setNormalizer($option, $normalizer);
@ -35,7 +35,7 @@ class OptionsResolverWrapper extends OptionsResolver
return $this;
}
public function setAllowedValues($option, $allowedValues)
public function setAllowedValues(string $option, $allowedValues)
{
try {
parent::setAllowedValues($option, $allowedValues);
@ -46,7 +46,7 @@ class OptionsResolverWrapper extends OptionsResolver
return $this;
}
public function addAllowedValues($option, $allowedValues)
public function addAllowedValues(string $option, $allowedValues)
{
try {
parent::addAllowedValues($option, $allowedValues);
@ -57,7 +57,7 @@ class OptionsResolverWrapper extends OptionsResolver
return $this;
}
public function setAllowedTypes($option, $allowedTypes)
public function setAllowedTypes(string $option, $allowedTypes)
{
try {
parent::setAllowedTypes($option, $allowedTypes);
@ -68,7 +68,7 @@ class OptionsResolverWrapper extends OptionsResolver
return $this;
}
public function addAllowedTypes($option, $allowedTypes)
public function addAllowedTypes(string $option, $allowedTypes)
{
try {
parent::addAllowedTypes($option, $allowedTypes);

View File

@ -31,7 +31,7 @@ class StringUtil
*
* @return string
*/
public static function trim($string)
public static function trim(string $string)
{
if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $string)) {
return $result;
@ -47,7 +47,7 @@ class StringUtil
*
* @return string|null The block prefix or null if not a valid FQCN
*/
public static function fqcnToBlockPrefix($fqcn)
public static function fqcnToBlockPrefix(string $fqcn)
{
// Non-greedy ("+?") to match "type" suffix, if present
if (preg_match('~([^\\\\]+?)(type)?$~i', $fqcn, $matches)) {

View File

@ -19,10 +19,10 @@
"php": "^7.2.9",
"symfony/event-dispatcher": "^4.4|^5.0",
"symfony/intl": "^4.4|^5.0",
"symfony/options-resolver": "^4.4|^5.0",
"symfony/options-resolver": "^5.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0",
"symfony/property-access": "^4.4|^5.0",
"symfony/property-access": "^5.0",
"symfony/service-contracts": "~1.1"
},
"require-dev": {