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: OptionsResolver.php
+16-14
Original file line number
Diff line number
Diff line change
@@ -921,7 +921,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
921
921
922
922
// Validate the type of the resolved option
923
923
if (isset($this->allowedTypes[$option])) {
924
-
$valid = false;
924
+
$valid = true;
925
925
$invalidTypes = [];
926
926
927
927
foreach ($this->allowedTypes[$option] as$type) {
@@ -933,13 +933,18 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
933
933
}
934
934
935
935
if (!$valid) {
936
-
$keys = array_keys($invalidTypes);
937
-
938
-
if (1 === \count($keys) && '[]' === substr($keys[0], -2)) {
939
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $this->formatOptions([$option]), $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), $keys[0]));
936
+
$fmtActualValue = $this->formatValue($value);
937
+
$fmtAllowedTypes = implode('" or "', $this->allowedTypes[$option]);
if (\is_array($value) && $allowedContainsArrayType) {
944
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
940
945
}
941
946
942
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $this->formatOptions([$option]), $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), implode('|', array_keys($invalidTypes))));
947
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $this->formatOptions([$option]), $fmtActualValue, $fmtAllowedTypes, $fmtProvidedTypes));
943
948
}
944
949
}
945
950
@@ -1044,26 +1049,23 @@ private function verifyTypes(string $type, $value, array &$invalidTypes, int $le
1044
1049
{
1045
1050
if (\is_array($value) && '[]' === substr($type, -2)) {
1046
1051
$type = substr($type, 0, -2);
1052
+
$valid = true;
1047
1053
1048
1054
foreach ($valueas$val) {
1049
1055
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