@@ -149,45 +149,75 @@ function () use ($level): string {
149149 return implode ('& ' , $ typeNames );
150150 },
151151 function () use ($ level ): string {
152- $ typeNames = [];
153- $ accessoryTypes = [];
154- foreach ($ this ->types as $ type ) {
155- if ($ type instanceof AccessoryNonEmptyStringType || $ type instanceof AccessoryLiteralStringType) {
156- $ accessoryTypes [] = $ type ;
157- }
158- if ($ type instanceof AccessoryType && !$ type instanceof AccessoryNumericStringType && !$ type instanceof NonEmptyArrayType && !$ type instanceof AccessoryNonEmptyStringType) {
159- continue ;
160- }
161- $ typeNames [] = $ type ->describe ($ level );
162- }
163-
164- if (count ($ accessoryTypes ) > 0 ) {
165- return implode ('& ' , array_map (static function (Type $ type ) use ($ level ): string {
166- return $ type ->describe ($ level );
167- }, $ accessoryTypes ));
168- }
169-
170- return implode ('& ' , $ typeNames );
152+ return $ this ->describeItself ($ level , true );
171153 },
172154 function () use ($ level ): string {
173- $ typeNames = [];
174- $ accessoryTypes = [];
175- foreach ($ this ->types as $ type ) {
176- if ($ type instanceof AccessoryNonEmptyStringType || $ type instanceof AccessoryLiteralStringType) {
177- $ accessoryTypes [] = $ type ;
155+ return $ this ->describeItself ($ level , false );
156+ }
157+ );
158+ }
159+
160+ private function describeItself (VerbosityLevel $ level , bool $ skipAccessoryTypes ): string
161+ {
162+ $ typesToDescribe = [];
163+ $ skipTypeNames = [];
164+ foreach ($ this ->types as $ type ) {
165+ if ($ type instanceof AccessoryNonEmptyStringType || $ type instanceof AccessoryLiteralStringType || $ type instanceof AccessoryNumericStringType) {
166+ $ typesToDescribe [] = $ type ;
167+ $ skipTypeNames [] = 'string ' ;
168+ continue ;
169+ }
170+ if ($ type instanceof NonEmptyArrayType) {
171+ $ typesToDescribe [] = $ type ;
172+ $ skipTypeNames [] = 'array ' ;
173+ continue ;
174+ }
175+
176+ if ($ skipAccessoryTypes ) {
177+ continue ;
178+ }
179+
180+ if (!$ type instanceof AccessoryType) {
181+ continue ;
182+ }
183+
184+ $ typesToDescribe [] = $ type ;
185+ }
186+
187+ $ describedTypes = [];
188+ foreach ($ this ->types as $ type ) {
189+ if ($ type instanceof AccessoryType) {
190+ continue ;
191+ }
192+ $ typeDescription = $ type ->describe ($ level );
193+ if (
194+ substr ($ typeDescription , 0 , strlen ('array< ' )) === 'array< '
195+ && in_array ('array ' , $ skipTypeNames , true )
196+ ) {
197+ foreach ($ typesToDescribe as $ j => $ typeToDescribe ) {
198+ if (!$ typeToDescribe instanceof NonEmptyArrayType) {
199+ continue ;
178200 }
179- $ typeNames [] = $ type ->describe ($ level );
180- }
181201
182- if (count ($ accessoryTypes ) > 0 ) {
183- return implode ('& ' , array_map (static function (Type $ type ) use ($ level ): string {
184- return $ type ->describe ($ level );
185- }, $ accessoryTypes ));
202+ unset($ typesToDescribe [$ j ]);
186203 }
187204
188- return implode ('& ' , $ typeNames );
205+ $ describedTypes [] = 'non-empty-array< ' . substr ($ typeDescription , strlen ('array< ' ));
206+ continue ;
189207 }
190- );
208+
209+ if (in_array ($ typeDescription , $ skipTypeNames , true )) {
210+ continue ;
211+ }
212+
213+ $ describedTypes [] = $ type ->describe ($ level );
214+ }
215+
216+ foreach ($ typesToDescribe as $ typeToDescribe ) {
217+ $ describedTypes [] = $ typeToDescribe ->describe ($ level );
218+ }
219+
220+ return implode ('& ' , $ describedTypes );
191221 }
192222
193223 public function canAccessProperties (): TrinaryLogic
0 commit comments