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

Commit92b0da1

Browse files
raphaelvoisinnicolas-grekas
authored andcommitted
[PropertyInfo] Add PHP 8.0 promoted properties@param mutation support toPhpDocExtractor
1 parent77ec2ad commit92b0da1

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

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

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

77
* Add support for phpDocumentor and PHPStan pseudo-types
8+
* Add PHP 8.0 promoted properties`@param` mutation support to`PhpDocExtractor`
89

910
6.0
1011
---

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,11 @@ public function getTypes(string $class, string $property, array $context = []):
128128
returnnull;
129129
}
130130

131-
switch ($source) {
132-
caseself::PROPERTY:
133-
$tag ='var';
134-
break;
135-
136-
caseself::ACCESSOR:
137-
$tag ='return';
138-
break;
139-
140-
caseself::MUTATOR:
141-
$tag ='param';
142-
break;
143-
}
131+
$tag =match ($source) {
132+
self::PROPERTY =>'var',
133+
self::ACCESSOR =>'return',
134+
self::MUTATOR =>'param',
135+
};
144136

145137
$parentClass =null;
146138
$types = [];
@@ -249,9 +241,19 @@ private function getDocBlock(string $class, string $property): array
249241
return$this->docBlocks[$propertyHash];
250242
}
251243

244+
try {
245+
$reflectionProperty =new \ReflectionProperty($class,$property);
246+
}catch (\ReflectionException$e) {
247+
$reflectionProperty =null;
248+
}
249+
252250
$ucFirstProperty =ucfirst($property);
253251

254252
switch (true) {
253+
case$reflectionProperty?->isPromoted() &&$docBlock =$this->getDocBlockFromConstructor($class,$property):
254+
$data = [$docBlock,self::MUTATOR,null];
255+
break;
256+
255257
case$docBlock =$this->getDocBlockFromProperty($class,$property):
256258
$data = [$docBlock,self::PROPERTY,null];
257259
break;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1717
useSymfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
1818
useSymfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
19+
useSymfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
1920
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
2021
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
2122
useSymfony\Component\PropertyInfo\Type;
@@ -429,6 +430,22 @@ public function pseudoTypesProvider(): array
429430
['positiveInt', [newType(Type::BUILTIN_TYPE_INT,false,null)]],
430431
];
431432
}
433+
434+
/**
435+
* @dataProvider promotedPropertyProvider
436+
*/
437+
publicfunctiontestExtractPromotedProperty(string$property, ?array$types)
438+
{
439+
$this->assertEquals($types,$this->extractor->getTypes(Php80Dummy::class,$property));
440+
}
441+
442+
publicfunctionpromotedPropertyProvider():array
443+
{
444+
return [
445+
['promoted',null],
446+
['promotedAndMutated', [newType(Type::BUILTIN_TYPE_STRING)]],
447+
];
448+
}
432449
}
433450

434451
class EmptyDocBlock

‎src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ class Php80Dummy
66
{
77
publicmixed$mixedProperty;
88

9+
/**
10+
* @param string $promotedAndMutated
11+
*/
12+
publicfunction__construct(privatemixed$promoted,privatemixed$promotedAndMutated)
13+
{
14+
}
15+
916
publicfunctiongetFoo():array|null
1017
{
1118
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp