You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was squashed before being merged into the 3.4 branch (closes#30737).
Discussion
----------
[Validator] Improve constraint default option check
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Any constraint without default option used as annotation with unnamed first argument (for example, `@Assert\Collection(1)`) throws an exception with an ugly message `The options "" do not exist in constraint Collection`.
This PR makes constraint check the default option in the annotation case in the same way it checks it in the "real" code case. So the exception will be `No default option is configured for constraint Collection.`
Commits
-------
915912e [Validator] Improve constraint default option check
thrownewConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
138
+
if (null === $defaultOption) {
139
+
thrownewConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', \get_class($this)));
137
140
}
138
141
139
-
if (\array_key_exists($option, $knownOptions)) {
140
-
$this->$option = $options;
141
-
unset($missingOptions[$option]);
142
+
if (\array_key_exists($defaultOption, $knownOptions)) {
143
+
$this->$defaultOption = $options;
144
+
unset($missingOptions[$defaultOption]);
142
145
} else {
143
-
$invalidOptions[] = $option;
146
+
$invalidOptions[] = $defaultOption;
144
147
}
145
148
}
146
149
147
150
if (\count($invalidOptions) > 0) {
148
-
thrownewInvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
151
+
thrownewInvalidOptionsException(sprintf('The options "%s" do not exist in constraint "%s".', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
149
152
}
150
153
151
154
if (\count($missingOptions) > 0) {
152
-
thrownewMissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
155
+
thrownewMissingOptionsException(sprintf('The options "%s" must be set for constraint "%s".', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
153
156
}
154
157
}
155
158
@@ -173,7 +176,7 @@ public function __set($option, $value)
173
176
return;
174
177
}
175
178
176
-
thrownewInvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
179
+
thrownewInvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
177
180
}
178
181
179
182
/**
@@ -199,7 +202,7 @@ public function __get($option)
199
202
return$this->groups;
200
203
}
201
204
202
-
thrownewInvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), [$option]);
205
+
thrownewInvalidOptionsException(sprintf('The option "%s" does not exist in constraint "%s".', $option, \get_class($this)), [$option]);
0 commit comments