Skip to content

Commit e9454d8

Browse files
Christoph Harms-Ensinkjaapio
authored andcommitted
UPDATE Method.php, MethodTest.php
- Modify the RegEx, so that an annotation like `@method static $this myMethod()` is parsed correctly - Write a Unittest for that usecase
1 parent c14a4ab commit e9454d8

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/DocBlock/Tags/Method.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ public static function create(
9191
)?
9292
# Return type
9393
(?:
94-
(
95-
(?:[\w\|_\\\\]+)
96-
# array notation
97-
(?:\[\])*
94+
(
95+
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
96+
|
97+
(?:
98+
(?:[\w\|_\\\\]+)
99+
# array notation
100+
(?:\[\])*
101+
)
98102
)?
99103
\s+
100104
)?

tests/unit/DocBlock/Tags/MethodTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Reflection\Types\Integer;
2323
use phpDocumentor\Reflection\Types\Object_;
2424
use phpDocumentor\Reflection\Types\String_;
25+
use phpDocumentor\Reflection\Types\This;
2526
use phpDocumentor\Reflection\Types\Void_;
2627

2728
/**
@@ -276,6 +277,29 @@ public function testFactoryMethod()
276277
$this->assertSame($description, $fixture->getDescription());
277278
}
278279

280+
public function testReturnTypeThis()
281+
{
282+
$descriptionFactory = m::mock(DescriptionFactory::class);
283+
$resolver = new TypeResolver();
284+
$context = new Context('');
285+
286+
$description = new Description('');
287+
288+
$descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description);
289+
290+
$fixture = Method::create(
291+
'static $this myMethod()',
292+
$resolver,
293+
$descriptionFactory,
294+
$context
295+
);
296+
297+
$this->assertTrue($fixture->isStatic());
298+
$this->assertSame('static $this myMethod() ', (string)$fixture);
299+
$this->assertSame('myMethod', $fixture->getMethodName());
300+
$this->assertInstanceOf(This::class, $fixture->getReturnType());
301+
}
302+
279303
public function collectionReturnTypesProvider()
280304
{
281305
return [

0 commit comments

Comments
 (0)