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-14Lines changed: 16 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -919,7 +919,7 @@ public function offsetGet($option, bool $triggerDeprecation = true)
919
919
920
920
// Validate the type of the resolved option
921
921
if (isset($this->allowedTypes[$option])) {
922
-
$valid = false;
922
+
$valid = true;
923
923
$invalidTypes = [];
924
924
925
925
foreach ($this->allowedTypes[$option] as$type) {
@@ -931,13 +931,18 @@ public function offsetGet($option, bool $triggerDeprecation = true)
931
931
}
932
932
933
933
if (!$valid) {
934
-
$keys = array_keys($invalidTypes);
935
-
936
-
if (1 === \count($keys) && '[]' === substr($keys[0], -2)) {
937
-
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]));
934
+
$fmtActualValue = $this->formatValue($value);
935
+
$fmtAllowedTypes = implode('" or "', $this->allowedTypes[$option]);
if (\is_array($value) && $allowedContainsArrayType) {
942
+
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));
938
943
}
939
944
940
-
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))));
945
+
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));
941
946
}
942
947
}
943
948
@@ -1042,26 +1047,23 @@ private function verifyTypes(string $type, $value, array &$invalidTypes, int $le
1042
1047
{
1043
1048
if (\is_array($value) && '[]' === substr($type, -2)) {
1044
1049
$type = substr($type, 0, -2);
1050
+
$valid = true;
1045
1051
1046
1052
foreach ($valueas$val) {
1047
1053
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