8000 bug #50332 [PropertyInfo] Fix `PhpStanExtractor` when constructor has… · symfony/symfony@03aa9c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03aa9c1

Browse files
bug #50332 [PropertyInfo] Fix PhpStanExtractor when constructor has no docblock (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Fix `PhpStanExtractor` when constructor has no docblock | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Currently the `PhpStanExtractor::getTypesFromConstructor()` method throws an exception when a constructor has no docblock, instead of returning `null`: ``` PHPStan\PhpDocParser\Parser\ParserException: Unexpected token "", expected '/**' at offset 0 ``` Commits ------- a55feaa [PropertyInfo] Fix `PhpStanExtractor` when constructor has no docblock
2 parents 6166fc4 + a55feaa commit 03aa9c1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ private function getDocBlockFromConstructor(string $class, string $property): ?P
171171
return null;
172172
}
173173

174-
$rawDocNode = $reflectionConstructor->getDocComment();
174+
if (!$rawDocNode = $reflectionConstructor->getDocComment()) {
175+
return null;
176+
}
177+
175178
$tokens = new TokenIterator($this->lexer->tokenize($rawDocNode));
176179
$phpDocNode = $this->phpDocParser->parse($tokens);
177180
$tokens->consumeTokenType(Lexer::TOKEN_END);

src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1616
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
17+
use Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithoutDocBlock;
1718
use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
1819
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1920
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
@@ -353,6 +354,14 @@ public function testExtractConstructorTypes($property, array $type = null)
353354
$this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy', $property));
354355
}
355356

357+
/**
358+
* @dataProvider constructorTypesProvider
359+
*/
360+
public function testExtractConstructorTypesReturnNullOnEmptyDocBlock($property)
361+
{
362+
$this->assertNull($this->extractor->getTypesFromConstructor(ConstructorDummyWithoutDocBlock::class, $property));
363+
}
364+
356365
public static function constructorTypesProvider()
357366
{
358367
return [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
class ConstructorDummyWithoutDocBlock
15+
{
16+
public function __construct(\DateTimeZone $timezone, $date, $dateObject, \DateTimeImmutable $dateTime, $mixed)
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)
0