当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionMethod::hasReturnType方法代码示例

本文整理汇总了PHP中ReflectionMethod::hasReturnType方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::hasReturnType方法的具体用法?PHP ReflectionMethod::hasReturnType怎么用?PHP ReflectionMethod::hasReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionMethod的用法示例。


在下文中一共展示了ReflectionMethod::hasReturnType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Initializes method prophecy.
  *
  * @param ObjectProphecy                        $objectProphecy
  * @param string                                $methodName
  * @param null|Argument\ArgumentsWildcard|array $arguments
  *
  * @throws \Prophecy\Exception\Doubler\MethodNotFoundException If method not found
  */
 public function __construct(ObjectProphecy $objectProphecy, $methodName, $arguments = null)
 {
     $double = $objectProphecy->reveal();
     if (!method_exists($double, $methodName)) {
         throw new MethodNotFoundException(sprintf('Method `%s::%s()` is not defined.', get_class($double), $methodName), get_class($double), $methodName, $arguments);
     }
     $this->objectProphecy = $objectProphecy;
     $this->methodName = $methodName;
     $reflectedMethod = new \ReflectionMethod($double, $methodName);
     if ($reflectedMethod->isFinal()) {
         throw new MethodProphecyException(sprintf("Can not add prophecy for a method `%s::%s()`\n" . "as it is a final method.", get_class($double), $methodName), $this);
     }
     if (null !== $arguments) {
         $this->withArguments($arguments);
     }
     if (version_compare(PHP_VERSION, '7.0', '>=') && true === $reflectedMethod->hasReturnType()) {
         $type = (string) $reflectedMethod->getReturnType();
         $this->will(function () use($type) {
             switch ($type) {
                 case 'string':
                     return '';
                 case 'float':
                     return 0.0;
                 case 'int':
                     return 0;
                 case 'bool':
                     return false;
                 case 'array':
                     return array();
                 case 'callable':
                 case 'Closure':
                     return function () {
                     };
                 case 'Traversable':
                 case 'Generator':
                     // Remove eval() when minimum version >=5.5
                     /** @var callable $generator */
                     $generator = eval('return function () { yield; };');
                     return $generator();
                 default:
                     $prophet = new Prophet();
                     return $prophet->prophesize($type)->reveal();
             }
         });
     }
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:55,代码来源:MethodProphecy.php

示例2: describeMethod

 /**
  * @param $methodMirror
  *
  * @return string
  */
 protected function describeMethod(ReflectionMethod $methodMirror) : string
 {
     if ($methodMirror->isProtected() || $methodMirror->isPrivate()) {
         return '';
     }
     $this->parseDocComment($methodMirror->getDocComment(), 2);
     $output = "\t.. php:method:: " . $methodMirror->name . " ( ";
     $output .= $this->buildParameterList($methodMirror->getParameters()) . " )\n\n";
     $output .= $this->describeParameters($methodMirror->getParameters());
     if ($methodMirror->hasReturnType()) {
         $output .= "\t\t:returns: \n\t\t:rtype: {$methodMirror->getReturnType()}";
     }
     $output .= "\n\n";
     $output .= $this->currentDocString . "\n\n";
     return $output;
 }
开发者ID:titounnes,项目名称:CodeIgniter4,代码行数:21,代码来源:autodoc.php

示例3: hasReturnType

 /**
  * @param ReflectionMethod $method
  *
  * @return bool
  */
 private function hasReturnType(ReflectionMethod $method)
 {
     return method_exists('ReflectionMethod', 'hasReturnType') && $method->hasReturnType();
 }
开发者ID:ezrra,项目名称:PHP,代码行数:9,代码来源:Generator.php

示例4: buildMethodSignature

 protected function buildMethodSignature(\ReflectionMethod $method, bool $skipAbstract = false, bool $skipDefaultValues = false) : string
 {
     if ($method->isProtected()) {
         $code = 'protected ';
     } elseif ($method->isPrivate()) {
         $code = 'private ';
     } else {
         $code = 'public ';
     }
     if ($method->isAbstract()) {
         if (!$skipAbstract) {
             $code .= 'abstract ';
         }
     } elseif ($method->isFinal()) {
         $code .= 'final ';
     }
     if ($method->isStatic()) {
         $code .= 'static ';
     }
     $code .= 'function ';
     if ($method->returnsReference()) {
         $code .= '& ';
     }
     $code .= $method->getName() . '(';
     foreach ($method->getParameters() as $i => $param) {
         if ($i > 0) {
             $code .= ', ';
         }
         $code .= $this->buildParameterSignature($param, $skipDefaultValues);
     }
     $code .= ')';
     if ($method->hasReturnType()) {
         $type = $method->getReturnType();
         if ($type->isBuiltin) {
             $code .= ': ' . $type;
         } else {
             $code .= ': \\' . $type;
         }
     }
     return $code;
 }
开发者ID:koolkode,项目名称:util,代码行数:41,代码来源:ReflectionTrait.php

示例5: allowsReturnNull

 /**
  * @param ReflectionMethod $method
  *
  * @return bool
  */
 private function allowsReturnNull(ReflectionMethod $method)
 {
     return method_exists(ReflectionMethod::class, 'getReturnType') && method_exists(ReflectionType::class, 'allowsNull') && $method->hasReturnType() && $method->getReturnType()->allowsNull();
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:9,代码来源:Generator.php


注:本文中的ReflectionMethod::hasReturnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。