本文整理汇总了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();
}
});
}
}
示例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;
}
示例3: hasReturnType
/**
* @param ReflectionMethod $method
*
* @return bool
*/
private function hasReturnType(ReflectionMethod $method)
{
return method_exists('ReflectionMethod', 'hasReturnType') && $method->hasReturnType();
}
示例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;
}
示例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();
}