8000 [PropertyInfo] Fix `PhpStanExtractor` when constructor has no docblock · symfony/symfony@a55feaa · GitHub
[go: up one dir, main page]

Skip to content

Commit a55feaa

Browse files
committed
[PropertyInfo] Fix PhpStanExtractor when constructor has no docblock
1 parent 6166fc4 commit a55feaa

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