Skip to content

Commit 18d7634

Browse files
committed
Fixed self deprecation of undefined form option
1 parent a77fc14 commit 18d7634

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

src/Form/Type/EnumType.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,16 @@ function (string $name): bool {
3939
function (Options $options): array {
4040
/** @var string $name */
4141
$name = $options['enum'];
42-
$choices = $this->enumRegistry->get($name)->getChoices();
4342

44-
if ($options['enum_choice_value'] === null) {
45-
foreach ($choices as $value) {
46-
if (!\is_scalar($value)) {
47-
@\trigger_error(
48-
'Not configuring the "enum_choice_value" option is deprecated.' .
49-
' It will default to "true" in 5.0.',
50-
\E_USER_DEPRECATED
51-
);
52-
break;
53-
}
54-
}
55-
}
56-
57-
return $choices;
43+
return $this->enumRegistry->get($name)->getChoices();
5844
}
5945
)
60-
->setAllowedTypes('enum_choice_value', ['bool', 'null'])
61-
->setDefault('enum_choice_value', null)
46+
->setAllowedTypes('enum_choice_value', ['bool'])
47+
->setDefault('enum_choice_value', true)
6248
->setDefault(
6349
'choice_value',
6450
static function (Options $options) {
65-
if ($options['enum_choice_value'] !== true) {
51+
if (!$options['enum_choice_value']) {
6652
return null;
6753
}
6854

src/Validator/Constraints/Enum.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public function __construct(
3232
array|null $groups = null,
3333
mixed $payload = null,
3434
) {
35-
if (\is_array($options) && [] !== $options) {
36-
trigger_deprecation(
35+
if (\is_array($options) && $options !== []) {
36+
\trigger_deprecation(
3737
'symfony/validator',
3838
'7.3',
3939
'Passing an array of options to configure the "%s" constraint is deprecated, use named arguments instead.',

tests/Integration/tests/PullRequestFormTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public function valid(): Generator
108108
{
109109
foreach ($this->classes() as [$class]) {
110110
yield [
111-
['status' => 0, 'labels' => ['bugfix', '1.x']],
111+
['status' => 'opened', 'labels' => ['bugfix', '1.x']],
112112
self::pullRequest($class),
113113
self::pullRequest($class, 'opened', ['bugfix', '1.x']),
114114
];
115115

116116
yield [
117-
['status' => 2, 'labels' => ['bugfix', '2.x']],
117+
['status' => 'closed', 'labels' => ['bugfix', '2.x']],
118118
self::pullRequest($class, 'opened', ['bugfix', '1.x']),
119119
self::pullRequest($class, 'closed', ['bugfix', '2.x']),
120120
];
@@ -171,7 +171,7 @@ public function invalid(): Generator
171171

172172
private static function pullRequest(
173173
string $class,
174-
string $status = null,
174+
string|null $status = null,
175175
array $labels = [],
176176
): MyCLabsPullRequest|NativeEnumPullRequest {
177177
return (match ($class) {

tests/Unit/Form/Type/EnumTypeTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,65 +61,65 @@ public static function submit(): \Generator
6161
{
6262
yield [
6363
StateEnum::class,
64-
[],
64+
['enum_choice_value' => false],
6565
'new',
6666
'new',
6767
];
6868
yield [
6969
StateEnum::class,
70-
['enum_choice_value' => true],
70+
[],
7171
'new',
7272
'new',
7373
];
7474

7575
yield [
7676
ActionEnum::class,
77-
[],
77+
['enum_choice_value' => false],
7878
1,
7979
Action::EDIT(),
8080
];
8181
yield [
8282
ActionEnum::class,
83-
['enum_choice_value' => true],
83+
[],
8484
'edit',
8585
Action::EDIT(),
8686
];
8787

8888
yield [
8989
Picture::class,
90-
[],
90+
['enum_choice_value' => false],
9191
0,
9292
Picture::Landscape,
9393
];
9494
yield [
9595
Picture::class,
96-
['enum_choice_value' => true],
96+
[],
9797
'Landscape',
9898
Picture::Landscape,
9999
];
100100

101101
yield [
102102
HTTPMethod::class,
103-
[],
103+
['enum_choice_value' => false],
104104
0,
105105
HTTPMethod::GET,
106106
];
107107
yield [
108108
HTTPMethod::class,
109-
['enum_choice_value' => true],
109+
[],
110110
'get',
111111
HTTPMethod::GET,
112112
];
113113

114114
yield [
115115
HTTPStatus::class,
116-
['enum_choice_value' => true],
116+
[],
117117
200,
118118
HTTPStatus::OK,
119119
];
120120
yield [
121121
HTTPStatus::class,
122-
[],
122+
['enum_choice_value' => false],
123123
0,
124124
HTTPStatus::OK,
125125
];

0 commit comments

Comments
 (0)