diff --git a/resources/views/helper.php b/resources/views/helper.php index d5bdda2..04f9071 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -36,7 +36,10 @@ namespace { //Method inherited from getDeclaringClass() ?> - shouldReturn() ? 'return ': '' ?>getRoot() ?>::getRealName() ?>(getParams() ?>); + isInstanceCall()):?> + /** @var getRoot()?> $instance */ + + shouldReturn() ? 'return ': '' ?>getRootMethodCall() ?>; } } @@ -57,8 +60,11 @@ namespace { //Method inherited from getDeclaringClass() ?> - - shouldReturn() ? 'return ': '' ?>getRoot() ?>::getRealName() ?>(getParams() ?>); + + isInstanceCall()):?> + /** @var getRoot()?> $instance */ + + shouldReturn() ? 'return ': '' ?>getRootMethodCall() ?>; } } diff --git a/src/Method.php b/src/Method.php index 70b7f14..033f70c 100644 --- a/src/Method.php +++ b/src/Method.php @@ -34,6 +34,7 @@ class Method protected $interfaces = array(); protected $real_name; protected $return = null; + protected $root; /** * @param \ReflectionMethod|\ReflectionFunctionAbstract $method @@ -50,6 +51,9 @@ class Method $this->real_name = $method->isClosure() ? $this->name : $method->name; $this->initClassDefinedProperties($method, $class); + //Reference the 'real' function in the declaring class + $this->root = '\\' . ltrim($class->getName(), '\\'); + //Create a DocBlock and serializer instance $this->initPhpDoc($method); @@ -66,9 +70,6 @@ class Method //Make the method static $this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc)); - - //Reference the 'real' function in the declaring class - $this->root = '\\' . ltrim($class->getName(), '\\'); } /** @@ -110,6 +111,26 @@ class Method return $this->root; } + /** + * @return bool + */ + public function isInstanceCall() + { + return ! ($this->method->isClosure() || $this->method->isStatic()); + } + + /** + * @return string + */ + public function getRootMethodCall() + { + if ($this->isInstanceCall()) { + return "\$instance->{$this->getRealName()}({$this->getParams()})"; + } else { + return "{$this->getRoot()}::{$this->getRealName()}({$this->getParams()})"; + } + } + /** * Get the docblock for this method * @@ -243,6 +264,10 @@ class Method // Set the changed content $tag->setContent($returnValue . ' ' . $tag->getDescription()); $this->return = $returnValue; + + if ($tag->getType() === '$this') { + $tag->setType($this->root); + } } else { $this->return = null; }