@@ -29,6 +29,23 @@ class Common
2929 'callable ' ,
3030 ];
3131
32+ /**
33+ * An array of short variable types for param/var we will check.
34+ *
35+ * @var string[]
36+ */
37+ public static $ allowedShortTypes = [
38+ 'array ' ,
39+ 'bool ' ,
40+ 'float ' ,
41+ 'int ' ,
42+ 'mixed ' ,
43+ 'object ' ,
44+ 'string ' ,
45+ 'resource ' ,
46+ 'callable ' ,
47+ ];
48+
3249
3350 /**
3451 * Return TRUE if the path is a PHAR file.
@@ -389,31 +406,48 @@ public static function isUnderscoreName($string)
389406 * If type is not one of the standard types, it must be a custom type.
390407 * Returns the correct type name suggestion if type name is invalid.
391408 *
392- * @param string $varType The variable type to process.
409+ * @param string $varType The variable type to process.
410+ * @param boolean $useShortTypes Whether to use short forms of type keywords.
393411 *
394412 * @return string
395413 */
396- public static function suggestType ($ varType )
414+ public static function suggestType ($ varType, $ useShortTypes = false )
397415 {
398416 if ($ varType === '' ) {
399417 return '' ;
400418 }
401419
402- if (in_array ($ varType , self ::$ allowedTypes , true ) === true ) {
420+ if ($ useShortTypes === true ) {
421+ $ allowedTypes = self ::$ allowedShortTypes ;
422+ } else {
423+ $ allowedTypes = self ::$ allowedTypes ;
424+ }
425+
426+ if (in_array ($ varType , $ allowedTypes , true ) === true ) {
403427 return $ varType ;
404428 } else {
405429 $ lowerVarType = strtolower ($ varType );
406430 switch ($ lowerVarType ) {
407431 case 'bool ' :
408432 case 'boolean ' :
409- return 'boolean ' ;
433+ if ($ useShortTypes === true ) {
434+ return 'bool ' ;
435+ } else {
436+ return 'boolean ' ;
437+ }
438+
410439 case 'double ' :
411440 case 'real ' :
412441 case 'float ' :
413442 return 'float ' ;
414443 case 'int ' :
415444 case 'integer ' :
416- return 'integer ' ;
445+ if ($ useShortTypes === true ) {
446+ return 'int ' ;
447+ } else {
448+ return 'integer ' ;
449+ }
450+
417451 case 'array() ' :
418452 case 'array ' :
419453 return 'array ' ;
@@ -435,8 +469,8 @@ public static function suggestType($varType)
435469 $ type2 = $ matches [3 ];
436470 }
437471
438- $ type1 = self ::suggestType ($ type1 );
439- $ type2 = self ::suggestType ($ type2 );
472+ $ type1 = self ::suggestType ($ type1, $ useShortTypes );
473+ $ type2 = self ::suggestType ($ type2, $ useShortTypes );
440474 if ($ type2 !== '' ) {
441475 $ type2 = ' => ' .$ type2 ;
442476 }
@@ -445,7 +479,7 @@ public static function suggestType($varType)
445479 } else {
446480 return 'array ' ;
447481 }//end if
448- } else if (in_array ($ lowerVarType , self :: $ allowedTypes , true ) === true ) {
482+ } else if (in_array ($ lowerVarType , $ allowedTypes , true ) === true ) {
449483 // A valid type, but not lower cased.
450484 return $ lowerVarType ;
451485 } else {
0 commit comments