@@ -1141,15 +1141,8 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
11411141
11421142 private function verifyTypes (string $ type , mixed $ value , ?array &$ invalidTypes = null , int $ level = 0 ): bool
11431143 {
1144- if (str_starts_with ($ type , '( ' ) && str_ends_with ($ type , ') ' )) {
1145- $ substr = substr ($ type , 1 , -1 );
1146-
1147- // Ensure we didn't simplify `(A)|(B)` into `A)|(B`
1148- $ openingPos = strpos ($ substr , '( ' );
1149- $ closingPos = strpos ($ substr , ') ' );
1150- if (false === $ closingPos || $ closingPos > $ openingPos ) {
1151- return $ this ->verifyTypes ($ substr , $ value , $ invalidTypes , $ level );
1152- }
1144+ if ($ this ->isEnclosedWithParenthesis ($ type )) {
1145+ return $ this ->verifyTypes (substr ($ type , 1 , -1 ), $ value , $ invalidTypes , $ level );
11531146 }
11541147
11551148 if (\is_array ($ value ) && str_ends_with ($ type , '[] ' )) {
@@ -1183,6 +1176,26 @@ private function verifyTypes(string $type, mixed $value, ?array &$invalidTypes =
11831176 return false ;
11841177 }
11851178
1179+ private function isEnclosedWithParenthesis (string $ string ): bool
1180+ {
1181+ if (!str_starts_with ($ string , '( ' ) || !str_ends_with ($ string , ') ' )) {
1182+ return false ;
1183+ }
1184+
1185+ $ openedParenthesis = 1 ;
1186+ $ i = 1 ;
1187+ while (isset (
8000
$ string [$ i ]) && $ openedParenthesis > 0 ) {
1188+ if ($ string [$ i ] === '( ' ) {
1189+ $ openedParenthesis ++;
1190+ } elseif ($ string [$ i ] === ') ' ) {
1191+ $ openedParenthesis --;
1192+ }
1193+ $ i ++;
1194+ }
1195+
1196+ return $ i === strlen ($ string );
1197+ }
1198+
11861199 /**
11871200 * Returns whether a resolved option with the given name exists.
11881201 *
0 commit comments