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
Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+16-14Lines changed: 16 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -917,7 +917,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
917
917
918
918
// Validate the type of the resolved option
919
919
if (isset($this->allowedTypes[$option])) {
920
-
$valid = false;
920
+
$valid = true;
921
921
$invalidTypes = [];
922
922
923
923
foreach ($this->allowedTypes[$option] as$type) {
@@ -929,13 +929,18 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
929
929
}
930
930
931
931
if (!$valid) {
932
-
$keys = array_keys($invalidTypes);
933
-
934
-
if (1 === \count($keys) && '[]' === substr($keys[0], -2)) {
935
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $option, $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), $keys[0]));
932
+
$fmtActualValue = $this->formatValue($value);
933
+
$fmtAllowedTypes = implode('" or "', $this->allowedTypes[$option]);
if (\is_array($value) && $allowedContainsArrayType) {
940
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $option, $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
936
941
}
937
942
938
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $option, $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), implode('|', array_keys($invalidTypes))));
943
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $option, $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
939
944
}
940
945
}
941
946
@@ -1040,26 +1045,23 @@ private function verifyTypes(string $type, $value, array &$invalidTypes, int $le
1040
1045
{
1041
1046
if (\is_array($value) && '[]' === substr($type, -2)) {
1042
1047
$type = substr($type, 0, -2);
1048
+
$valid = true;
1043
1049
1044
1050
foreach ($valueas$val) {
1045
1051
if (!$this->verifyTypes($type, $val, $invalidTypes, $level + 1)) {
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTime[]".');
779
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTime".');
780
780
$this->resolver->setDefined('foo');
781
781
$this->resolver->setAllowedTypes('foo', 'int[]');
782
782
@@ -796,7 +796,7 @@ public function testResolveFailsWithNonArray()
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass[]".');
799
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass|array|DateTime".');
800
800
$this->resolver->setDefined('foo');
801
801
$this->resolver->setAllowedTypes('foo', 'int[]');
802
802
$values = range(1, 5);
@@ -811,7 +811,7 @@ public function testResolveFailsIfTypedArrayContainsInvalidTypes()
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "double[][]".');
814
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "double".');
@@ -847,6 +847,11 @@ public function provideInvalidTypes()
847
847
[42, 'string', 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".'],
848
848
[null, 'string', 'The option "option" with value null is expected to be of type "string", but is of type "NULL".'],
849
849
['bar', '\stdClass', 'The option "option" with value "bar" is expected to be of type "\stdClass", but is of type "string".'],
850
+
[['foo', 12], 'string[]', 'The option "option" with value array is expected to be of type "string[]", but one of the elements is of type "integer".'],
851
+
[123, ['string[]', 'string'], 'The option "option" with value 123 is expected to be of type "string[]" or "string", but is of type "integer".'],
852
+
[[null], ['string[]', 'string'], 'The option "option" with value array is expected to be of type "string[]" or "string", but one of the elements is of type "NULL".'],
853
+
[['string', null], ['string[]', 'string'], 'The option "option" with value array is expected to be of type "string[]" or "string", but one of the elements is of type "NULL".'],
854
+
[[\stdClass::class], ['string'], 'The option "option" with value array is expected to be of type "string", but is of type "array".'],
850
855
];
851
856
}
852
857
@@ -1898,7 +1903,7 @@ public function testNested2Arrays()
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "float[][][][]", but one of the elements is of type "integer[][][][]".');
1906
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "float[][][][]", but one of the elements is of type "integer".');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".');
1924
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean|string|array".');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".');
1937
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean|string|array".');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "string[][]".');
1950
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "string|integer".');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "integer[][][]".');
1963
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "integer".');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[]", but one of the elements is of type "array[]".');
1977
+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[]", but one of the elements is of type "array".');
0 commit comments