@@ -203,20 +203,25 @@ function get_type_by_string($str) { /* {{{ */
203
203
/* }}} */
204
204
205
205
/** @return string|null */
206
- function get_type_as_string (ReflectionType $ type = null ) { /* {{{ */
206
+ function get_type_as_xml_string (ReflectionType $ type = null ) { /* {{{ */
207
207
if ($ type instanceof ReflectionNamedType) {
208
- $ ret = $ type ->getName ();
208
+ $ ret = " <type> { $ type ->getName ()} </type> " ;
209
209
if ($ type ->allowsNull ()) {
210
- $ ret .= ' | null' ;
210
+ $ ret = " <type class= \" union \" > { $ ret } <type> null</type></type> " ;
211
211
}
212
212
return $ ret ;
213
213
}
214
214
if ($ type instanceof ReflectionUnionType) {
215
- $ types = array_map (function ($ type ) {return $ type ->getName ();}, $ type ->getTypes ());
216
- return implode ('| ' , $ types );
215
+ $ types = array_map (function ($ type ) {return "<type> {$ type ->getName ()}</type> " ;}, $ type ->getTypes ());
216
+ $ ret = implode ('' , $ types );
217
+ if (count ($ types ) > 1 ) {
218
+ $ ret = "<type class= \"union \"> {$ ret }</type> " ;
219
+ }
220
+ return $ ret ;
217
221
}
218
222
if ($ type instanceof ReflectionType) {
219
- return (string ) $ type ;
223
+ $ ret = (string ) $ type ;
224
+ return "<type> {$ ret }</type> " ;
220
225
}
221
226
return null ;
222
227
}
@@ -243,16 +248,16 @@ function create_markup_to_params(array $params, $ident) { /* {{{ */
243
248
$ markup = "" ;
244
249
foreach ($ params as $ param ) {
245
250
/* Parameter type */
246
- $ type = get_type_as_string ($ param ->getType ());
251
+ $ type = get_type_as_xml_string ($ param ->getType ());
247
252
if ($ type === null ) {
248
- $ type = 'mixed ' ;
253
+ $ type = '<type> mixed</type> ' ;
249
254
if (!$ param ->getName ()) {
250
255
add_warning (sprintf ("Parameter name not found, param%d used " , $ count ));
251
256
}
252
257
add_warning (sprintf ("Type hint for parameter `%s' not found, 'mixed' used " , ($ param ->getName () ? $ param ->getName () : $ count )));
253
258
}
254
259
255
- $ markup .= sprintf ("%s<methodparam%s><type>%s</type> <parameter%s>%s</parameter></methodparam> " . PHP_EOL ,
260
+ $ markup .= sprintf ("%s<methodparam%s>%s <parameter%s>%s</parameter></methodparam> " . PHP_EOL ,
256
261
($ markup ? str_repeat (' ' , $ ident ) : '' ),
257
262
($ param ->isOptional () ? ' choice="opt" ' : '' ),
258
263
$ type ,
@@ -333,12 +338,12 @@ function gen_function_markup(ReflectionFunction $function, $content) { /* {{{ */
333
338
$ content = preg_replace ('/\{FUNCTION_NAME\}/ ' , $ function ->getName (), $ content );
334
339
335
340
/* {RETURN_TYPE} */
336
- $ type = get_type_as_string ($ function ->getReturnType ());
341
+ $ type = get_type_as_xml_string ($ function ->getReturnType ());
337
342
if ($ type === null ) {
338
- $ type = 'mixed ' ;
343
+ $ type = '<type> mixed</type> ' ;
339
344
add_warning (sprintf ("Return type hint for function `%s' not found, 'mixed' used " , $ function ->getName ()));
340
345
}
341
- $ content = preg_replace ('/\{RETURN_TYPE\}/ ' , " <type> $ type</type> " , $ content , 1 );
346
+ $ content = preg_replace ('/\{RETURN_TYPE\}/ ' , $ type , $ content , 1 );
342
347
343
348
/* {FUNCTION_PARAMETERS}, {PARAMETERS_DESCRIPTION} */
344
349
$ content = create_markup_to_parameter_section ($ function , $ content );
@@ -368,12 +373,12 @@ function gen_method_markup(ReflectionMethod $method, $content) { /* {{{ */
368
373
369
374
/* {RETURN_TYPE} */
370
375
if (!$ method ->isConstructor ()) {
371
- $ type = get_type_as_string ($ method ->getReturnType ());
376
+ $ type = get_type_as_xml_string ($ method ->getReturnType ());
372
377
if ($ type === null ) {
373
- $ type = 'mixed ' ;
378
+ $ type = '<type> mixed</type> ' ;
374
379
add_warning (sprintf ("Return type hint for method `%s' not found, 'mixed' used " , $ method ->getName ()));
375
380
}
376
- $ content = preg_replace ('/\{RETURN_TYPE\}/ ' , " <type> $ type</type> " , $ content , 1 );
381
+ $ content = preg_replace ('/\{RETURN_TYPE\}/ ' , $ type , $ content , 1 );
377
382
} else {
378
383
$ content = preg_replace ('/\{RETURN_TYPE\}/ ' , '' , $ content , 1 );
379
384
}
0 commit comments