Skip to content

Commit 491c2f4

Browse files
bug #62717 [PropertyInfo] fix @var tag support for PhpStanExtractor (qconer)
This PR was merged into the 6.4 branch. Discussion ---------- [PropertyInfo] fix ``@var`` tag support for `PhpStanExtractor` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #62712 | License | MIT added fallback when no __construct PHPDocBlock exists duplicate for #62713 Commits ------- 4158e3b fix: fix property info var tag extractor
2 parents 45d7ec5 + 4158e3b commit 491c2f4

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function getTypes(string $class, string $property, array $context = []):
154154
public function getTypesFromConstructor(string $class, string $property): ?array
155155
{
156156
if (null === $tagDocNode = $this->getDocBlockFromConstructor($class, $property)) {
157-
return null;
157+
return $this->getTypes($class, $property);
158158
}
159159

160160
$types = [];

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,29 @@ public static function constructorTypesProvider()
370370
['date', [new Type(Type::BUILTIN_TYPE_INT)]],
371371
['timezone', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeZone')]],
372372
['dateObject', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeInterface')]],
373-
['dateTime', null],
373+
['dateTime', [new Type(Type::BUILTIN_TYPE_INT)]],
374374
['ddd', null],
375375
];
376376
}
377377

378+
/**
379+
* @dataProvider provideConstructorTypesWithOnlyVarTags
380+
*/
381+
public function testExtractConstructorTypesWithOnlyVarTags($property, ?array $type = null)
382+
{
383+
$this->assertEquals($type, $this->extractor->getTypesFromConstructor('Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummyWithVarTagsDocBlock', $property));
384+
}
385+
386+
public static function provideConstructorTypesWithOnlyVarTags()
387+
{
388+
yield ['date', [new Type(Type::BUILTIN_TYPE_INT)]];
389+
yield ['dateObject', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeInterface')]];
390+
yield ['objectsArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\ConstructorDummy'))]];
391+
yield ['dateTime', null];
392+
yield ['mixed', null];
393+
yield ['timezone', null];
394+
}
395+
378396
/**
379397
* @dataProvider unionTypesProvider
380398
*/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
15+
class ConstructorDummyWithVarTagsDocBlock
16+
{
17+
public function __construct(
18+
public \DateTimeZone $timezone,
19+
/** @var int */
20+
public $date,
21+
/** @var \DateTimeInterface */
22+
public $dateObject,
23+
public \DateTimeImmutable $dateTime,
24+
public $mixed,
25+
/** @var ConstructorDummy[] */
26+
public array $objectsArray,
27+
)
28+
{
29+
}
30+
}

0 commit comments

Comments
 (0)