Skip to content

Commit

Permalink
minor #32828 [Form] update type of form $name arguments (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

[Form] update type of form $name arguments

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32821
| License       | MIT
| Doc PR        | -

An alternative to #32821: where a string is expected, passing an int is fine, per PHP casting rules.

Commits
-------

6d4dcad [Form] update type of form $name arguments
  • Loading branch information
nicolas-grekas committed Jul 31, 2019
2 parents dfce45b + 6d4dcad commit bcfc7a4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/Symfony/Component/Form/ButtonBuilder.php
Expand Up @@ -71,9 +71,8 @@ public function __construct($name, array $options = [])
*
* This method should not be invoked.
*
* @param string|int|FormBuilderInterface $child
* @param string|FormTypeInterface $type
* @param array $options
* @param string|FormBuilderInterface $child
* @param string|FormTypeInterface $type
*
* @throws BadMethodCallException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Form.php
Expand Up @@ -819,7 +819,7 @@ public function add($child, $type = null, array $options = [])

if (!$child instanceof FormInterface) {
if (!\is_string($child) && !\is_int($child)) {
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormInterface');
throw new UnexpectedTypeException($child, 'string or Symfony\Component\Form\FormInterface');
}

if (null !== $type && !\is_string($type) && !$type instanceof FormTypeInterface) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormBuilder.php
Expand Up @@ -70,7 +70,7 @@ public function add($child, $type = null, array $options = [])
}

if (!\is_string($child) && !\is_int($child)) {
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilderInterface');
throw new UnexpectedTypeException($child, 'string or Symfony\Component\Form\FormBuilderInterface');
}

if (null !== $type && !\is_string($type) && !$type instanceof FormTypeInterface) {
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Form/FormBuilderInterface.php
Expand Up @@ -23,9 +23,8 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
* If you add a nested group, this group should also be represented in the
* object hierarchy.
*
* @param string|int|FormBuilderInterface $child
* @param string|null $type
* @param array $options
* @param string|FormBuilderInterface $child
* @param string|null $type
*
* @return self
*/
Expand All @@ -34,9 +33,8 @@ public function add($child, $type = null, array $options = []);
/**
* Creates a form builder.
*
* @param string $name The name of the form or the name of the property
* @param string|null $type The type of the form or null if name is a property
* @param array $options The options
* @param string $name The name of the form or the name of the property
* @param string|null $type The type of the form or null if name is a property
*
* @return self
*/
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Form/FormConfigBuilder.php
Expand Up @@ -121,10 +121,8 @@ class FormConfigBuilder implements FormConfigBuilderInterface
/**
* Creates an empty form configuration.
*
* @param string|int $name The form name
* @param string|null $dataClass The class of the form's data
* @param EventDispatcherInterface $dispatcher The event dispatcher
* @param array $options The form options
* @param string $name The form name
* @param string|null $dataClass The class of the form's data
*
* @throws InvalidArgumentException if the data class is not a valid class or if
* the name contains invalid characters
Expand Down Expand Up @@ -787,15 +785,15 @@ public function getFormConfig()
/**
* Validates whether the given variable is a valid form name.
*
* @param string|int|null $name The tested form name
* @param string|null $name The tested form name
*
* @throws UnexpectedTypeException if the name is not a string or an integer
* @throws InvalidArgumentException if the name contains invalid characters
*/
public static function validateName($name)
{
if (null !== $name && !\is_string($name) && !\is_int($name)) {
throw new UnexpectedTypeException($name, 'string, integer or null');
throw new UnexpectedTypeException($name, 'string or null');
}

if (!self::isValidName($name)) {
Expand Down
14 changes: 6 additions & 8 deletions src/Symfony/Component/Form/FormFactoryInterface.php
Expand Up @@ -36,10 +36,9 @@ public function create($type = 'Symfony\Component\Form\Extension\Core\Type\FormT
*
* @see createNamedBuilder()
*
* @param string|int $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
* @param array $options The options
* @param string $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
*
* @return FormInterface The form
*
Expand Down Expand Up @@ -79,10 +78,9 @@ public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Typ
/**
* Returns a form builder.
*
* @param string|int $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
* @param array $options The options
* @param string $name The name of the form
* @param string $type The type of the form
* @param mixed $data The initial data
*
* @return FormBuilderInterface The form builder
*
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Form/FormInterface.php
Expand Up @@ -43,9 +43,9 @@ public function getParent();
/**
* Adds or replaces a child to the form.
*
* @param FormInterface|string|int $child The FormInterface instance or the name of the child
* @param string|null $type The child's type, if a name was passed
* @param array $options The child's options, if a name was passed
* @param FormInterface|string $child The FormInterface instance or the name of the child
* @param string|null $type The child's type, if a name was passed
* @param array $options The child's options, if a name was passed
*
* @return $this
*
Expand Down

0 comments on commit bcfc7a4

Please sign in to comment.