Example #1
0
 /**
  * @param ReflectionFunctionAbstract $function
  * @return string
  */
 private function _scanFunction(ReflectionFunctionAbstract $function, $class_name = "")
 {
     $params = [];
     foreach ($function->getParameters() as $param) {
         /* @var ReflectionParameter $param */
         $type = "";
         $param_name = "\$" . $param->name;
         if ($param->getClass()) {
             $type = $param->getClass()->name;
         } elseif ($param->hasType()) {
             $type = $param->getType();
         } elseif ($param->isArray()) {
             $type = "Array";
         } elseif ($param->isCallable()) {
             $type = "Callable";
         }
         if ($param->isVariadic()) {
             $param_name = "..." . $param_name;
         }
         if ($type) {
             $param_name = $type . " " . $param_name;
         }
         if ($param->isOptional()) {
             $params[] = "[ " . $param_name . " ]";
         } else {
             $params[] = $param_name;
         }
     }
     if ($function->hasReturnType()) {
         $return = " : " . $function->getReturnType();
     } else {
         $return = "";
     }
     $declare = $function->name;
     if ($function instanceof ReflectionFunction) {
         $declare = "function {$function->name}";
     } elseif ($function instanceof ReflectionMethod) {
         $mods = implode(' ', Reflection::getModifierNames($function->getModifiers()));
         if ($function->class !== $class_name) {
             $declare = "  method {$mods} {$function->class}::{$function->name}";
         } else {
             $declare = "  method {$mods} {$function->name}";
         }
     }
     return "{$declare}(" . implode(", ", $params) . "){$return}";
 }