Esempio n. 1
0
 /**
  * Extract the return type of a method.
  *
  * @param  objedct $method A instance of `ReflectionMethod`.
  * @return string          The return type.
  */
 protected static function _generateReturnType($method)
 {
     if (Suite::$PHP < 7) {
         return '';
     }
     $type = $method->getReturnType();
     if ($type) {
         if (!$type->isBuiltin()) {
             $type = '\\' . $type;
         }
         if (defined('HHVM_VERSION')) {
             $type = preg_replace('~\\\\?HH\\\\(mixed|void)?~', '', $type);
         }
     }
     return $type ? ": {$type} " : '';
 }
Esempio n. 2
0
 /**
  * Creates a method definition from a `ReflectionMethod` instance.
  *
  * @param  objedct $method A instance of `ReflectionMethod`.
  * @return string          The generated method.
  */
 protected static function _generateMethod($method, $callParent = false)
 {
     $result = join(' ', Reflection::getModifierNames($method->getModifiers()));
     $result = preg_replace('/abstract\\s*/', '', $result);
     $name = $method->getName();
     $parameters = static::_generateSignature($method);
     if (PHP_MAJOR_VERSION >= 7) {
         $type = $method->getReturnType();
         $type = $type ? ": {$type} " : '';
     } else {
         $type = '';
     }
     $body = "{$result} function {$name}({$parameters}) {$type}{";
     if ($callParent) {
         $parameters = static::_generateParameters($method);
         $body .= "return parent::{$name}({$parameters});";
     }
     return $body . "}";
 }