diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index d600aaa..061e815 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -91,10 +91,14 @@ final class Method extends BaseTag implements Factory\StaticMethod )? # Return type (?: - ( - (?:[\w\|_\\\\]+) - # array notation - (?:\[\])* + ( + (?:[\w\|_\\\\]*\$this[\w\|_\\\\]*) + | + (?: + (?:[\w\|_\\\\]+) + # array notation + (?:\[\])* + ) )? \s+ )? diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 5d6e981..ca6436c 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -22,6 +22,7 @@ use phpDocumentor\Reflection\Types\Context; use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\Object_; use phpDocumentor\Reflection\Types\String_; +use phpDocumentor\Reflection\Types\This; use phpDocumentor\Reflection\Types\Void_; /** @@ -276,6 +277,29 @@ class MethodTest extends \PHPUnit_Framework_TestCase $this->assertSame($description, $fixture->getDescription()); } + public function testReturnTypeThis() + { + $descriptionFactory = m::mock(DescriptionFactory::class); + $resolver = new TypeResolver(); + $context = new Context(''); + + $description = new Description(''); + + $descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description); + + $fixture = Method::create( + 'static $this myMethod()', + $resolver, + $descriptionFactory, + $context + ); + + $this->assertTrue($fixture->isStatic()); + $this->assertSame('static $this myMethod() ', (string)$fixture); + $this->assertSame('myMethod', $fixture->getMethodName()); + $this->assertInstanceOf(This::class, $fixture->getReturnType()); + } + public function collectionReturnTypesProvider() { return [