Skip to content

Commit edbf336

Browse files
Remove all "nullable-by-default-value" setters
1 parent a568717 commit edbf336

File tree

8 files changed

+24
-4
lines changed

8 files changed

+24
-4
lines changed

Button.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function offsetUnset(mixed $offset): void
8383

8484
public function setParent(FormInterface $parent = null): static
8585
{
86+
if (1 > \func_num_args()) {
87+
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
88+
}
8689
if ($this->submitted) {
8790
throw new AlreadySubmittedException('You cannot set the parent of a submitted button.');
8891
}

ButtonBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public function setAttributes(array $attributes): static
194194
*/
195195
public function setDataMapper(DataMapperInterface $dataMapper = null): static
196196
{
197+
if (1 > \func_num_args()) {
198+
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
199+
}
200+
197201
throw new BadMethodCallException('Buttons do not support data mappers.');
198202
}
199203

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ CHANGELOG
44
6.2
55
---
66

7-
* Allow passing `TranslatableInterface` objects to the `ChoiceView` label
8-
* Allow passing `TranslatableInterface` objects to the `help` option
7+
* Allow passing `TranslatableInterface` objects to the `ChoiceView` label
8+
* Allow passing `TranslatableInterface` objects to the `help` option
9+
* Deprecate calling `Button/Form::setParent()`, `ButtonBuilder/FormConfigBuilder::setDataMapper()`, `TransformationFailedException::setInvalidMessage()` without arguments
10+
* Change the signature of `FormConfigBuilderInterface::setDataMapper()` to `setDataMapper(?DataMapperInterface)`
11+
* Change the signature of `FormInterface::setParent()` to `setParent(?self)`
912

1013
6.1
1114
---

Exception/TransformationFailedException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function __construct(string $message = '', int $code = 0, \Throwable $pre
3636
*/
3737
public function setInvalidMessage(string $invalidMessage = null, array $invalidMessageParameters = []): void
3838
{
39+
if (1 > \func_num_args()) {
40+
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
41+
}
3942
$this->invalidMessage = $invalidMessage;
4043
$this->invalidMessageParameters = $invalidMessageParameters;
4144
}

Form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public function isDisabled(): bool
220220

221221
public function setParent(FormInterface $parent = null): static
222222
{
223+
if (1 > \func_num_args()) {
224+
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
225+
}
226+
223227
if ($this->submitted) {
224228
throw new AlreadySubmittedException('You cannot set the parent of a submitted form.');
225229
}

FormConfigBuilder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ public function setAttributes(array $attributes): static
340340

341341
public function setDataMapper(DataMapperInterface $dataMapper = null): static
342342
{
343+
if (1 > \func_num_args()) {
344+
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
345+
}
343346
if ($this->locked) {
344347
throw new BadMethodCallException('FormConfigBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
345348
}

FormConfigBuilderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function setAttributes(array $attributes): static;
100100
*
101101
* @return $this
102102
*/
103-
public function setDataMapper(DataMapperInterface $dataMapper = null): static;
103+
public function setDataMapper(?DataMapperInterface $dataMapper): static;
104104

105105
/**
106106
* Sets whether the form is disabled.

FormInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
3434
* @throws Exception\LogicException when trying to set a parent for a form with
3535
* an empty name
3636
*/
37-
public function setParent(self $parent = null): static;
37+
public function setParent(?self $parent): static;
3838

3939
/**
4040
* Returns the parent form.

0 commit comments

Comments
 (0)