Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8acf157

Browse files
simPodnicolas-grekas
authored andcommitted
[PropertyInfo] Add support for promoted properties in PhpStanExtractor
1 parent2a38810 commit8acf157

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

‎src/Symfony/Component/PropertyInfo/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add support for phpDocumentor and PHPStan pseudo-types
88
* Add PHP 8.0 promoted properties`@param` mutation support to`PhpDocExtractor`
9+
* Add PHP 8.0 promoted properties`@param` mutation support to`PhpStanExtractor`
910

1011
6.0
1112
---

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ private function getDocBlock(string $class, string $property): array
196196

197197
$ucFirstProperty =ucfirst($property);
198198

199-
if ([$docBlock,$declaringClass] =$this->getDocBlockFromProperty($class,$property)) {
200-
$data = [$docBlock,self::PROPERTY,null,$declaringClass];
199+
if ([$docBlock,$source,$declaringClass] =$this->getDocBlockFromProperty($class,$property)) {
200+
$data = [$docBlock,$source,null,$declaringClass];
201201
}elseif ([$docBlock,$_,$declaringClass] =$this->getDocBlockFromMethod($class,$ucFirstProperty,self::ACCESSOR)) {
202202
$data = [$docBlock,self::ACCESSOR,null,$declaringClass];
203203
}elseif ([$docBlock,$prefix,$declaringClass] =$this->getDocBlockFromMethod($class,$ucFirstProperty,self::MUTATOR)) {
@@ -210,7 +210,7 @@ private function getDocBlock(string $class, string $property): array
210210
}
211211

212212
/**
213-
* @return array{PhpDocNode, string}|null
213+
* @return array{PhpDocNode,int,string}|null
214214
*/
215215
privatefunctiongetDocBlockFromProperty(string$class,string$property): ?array
216216
{
@@ -221,15 +221,21 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra
221221
returnnull;
222222
}
223223

224-
if (null ===$rawDocNode =$reflectionProperty->getDocComment() ?:null) {
224+
$source =self::PROPERTY;
225+
226+
if ($reflectionProperty->isPromoted()) {
227+
$constructor =new \ReflectionMethod($class,'__construct');
228+
$rawDocNode =$constructor->getDocComment();
229+
$source =self::MUTATOR;
230+
}elseif (null ===$rawDocNode =$reflectionProperty->getDocComment() ?:null) {
225231
returnnull;
226232
}
227233

228234
$tokens =newTokenIterator($this->lexer->tokenize($rawDocNode));
229235
$phpDocNode =$this->phpDocParser->parse($tokens);
230236
$tokens->consumeTokenType(Lexer::TOKEN_END);
231237

232-
return [$phpDocNode,$reflectionProperty->class];
238+
return [$phpDocNode,$source,$reflectionProperty->class];
233239
}
234240

235241
/**

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
useSymfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
1818
useSymfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1919
useSymfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
20+
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
2021
useSymfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem;
2122
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2223
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
@@ -434,6 +435,21 @@ public function testDummyNamespaceWithProperty()
434435
$this->assertEquals('A\Property',$phpStanTypes[0]->getClassName());
435436
$this->assertEquals($phpDocTypes[0]->getClassName(),$phpStanTypes[0]->getClassName());
436437
}
438+
439+
/**
440+
* @dataProvider php80TypesProvider
441+
*/
442+
publicfunctiontestExtractPhp80Type($property,array$type =null)
443+
{
444+
$this->assertEquals($type,$this->extractor->getTypes(Php80Dummy::class,$property, []));
445+
}
446+
447+
publicfunctionphp80TypesProvider()
448+
{
449+
return [
450+
['promotedAndMutated', [newType(Type::BUILTIN_TYPE_STRING)]],
451+
];
452+
}
437453
}
438454

439455
class PhpStanOmittedParamTagTypeDocBlock

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp