3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Code\Reflection
;
12 use ReflectionFunction
;
13 use Zend\Code\Reflection\DocBlock\Tag\ReturnTag
;
15 class FunctionReflection
extends ReflectionFunction
implements ReflectionInterface
18 * Get function DocBlock
20 * @throws Exception\InvalidArgumentException
21 * @return DocBlockReflection
23 public function getDocBlock()
25 if ('' == ($comment = $this->getDocComment())) {
26 throw new Exception\
InvalidArgumentException(sprintf(
27 '%s does not have a DocBlock',
32 $instance = new DocBlockReflection($comment);
38 * Get start line (position) of function
40 * @param bool $includeDocComment
43 public function getStartLine($includeDocComment = false)
45 if ($includeDocComment) {
46 if ($this->getDocComment() != '') {
47 return $this->getDocBlock()->getStartLine();
51 return parent
::getStartLine();
55 * Get contents of function
57 * @param bool $includeDocBlock
60 public function getContents($includeDocBlock = true)
64 file($this->getFileName()),
65 $this->getStartLine($includeDocBlock),
66 ($this->getEndLine() - $this->getStartLine()),
73 * Get function parameters
75 * @return ParameterReflection[]
77 public function getParameters()
79 $phpReflections = parent
::getParameters();
80 $zendReflections = array();
81 while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
82 $instance = new ParameterReflection($this->getName(), $phpReflection->getName());
83 $zendReflections[] = $instance;
84 unset($phpReflection);
86 unset($phpReflections);
88 return $zendReflections;
94 * @throws Exception\InvalidArgumentException
97 public function getReturn()
99 $docBlock = $this->getDocBlock();
100 if (!$docBlock->hasTag('return')) {
101 throw new Exception\
InvalidArgumentException(
102 'Function does not specify an @return annotation tag; cannot determine return type'
106 $tag = $docBlock->getTag('return');
107 return new DocBlockReflection('@return ' . $tag->getDescription());
110 public function toString()
112 return $this->__toString();
116 * Required due to bug in php
120 public function __toString()
122 return parent
::__toString();