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

Commit1b358fe

Browse files
committed
bug#40175 [PropertyInfo]  use the right context for properties defined in traits (xabbuh)
This PR was merged into the 4.4 branch.Discussion----------[PropertyInfo]  use the right context for properties defined in traits| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#28732,#34191| License | MIT| Doc PR |Commits-------1572491 use the right context for properties defined in traits
2 parentsaa21944 +1572491 commit1b358fe

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,17 @@ private function getDocBlockFromProperty(string $class, string $property): ?DocB
201201
}
202202

203203
try {
204-
return$this->docBlockFactory->create($reflectionProperty,$this->createFromReflector($reflectionProperty->getDeclaringClass()));
204+
$reflector =$reflectionProperty->getDeclaringClass();
205+
206+
foreach ($reflector->getTraits()as$trait) {
207+
if ($trait->hasProperty($property)) {
208+
$reflector =$trait;
209+
210+
break;
211+
}
212+
}
213+
214+
return$this->docBlockFactory->create($reflectionProperty,$this->createFromReflector($reflector));
205215
}catch (\InvalidArgumentException$e) {
206216
returnnull;
207217
}catch (\RuntimeException$e) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
usephpDocumentor\Reflection\Types\Collection;
1717
usePHPUnit\Framework\TestCase;
1818
useSymfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
19+
useSymfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
20+
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
21+
useSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
1922
useSymfony\Component\PropertyInfo\Type;
2023

2124
/**
@@ -273,6 +276,23 @@ public function testDocBlockFallback($property, $types)
273276
$this->assertEquals($types,$this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback',$property));
274277
}
275278

279+
/**
280+
* @dataProvider propertiesDefinedByTraitsProvider
281+
*/
282+
publicfunctiontestPropertiesDefinedByTraits(string$property,Type$type)
283+
{
284+
$this->assertEquals([$type],$this->extractor->getTypes(DummyUsingTrait::class,$property));
285+
}
286+
287+
publicfunctionpropertiesDefinedByTraitsProvider():array
288+
{
289+
return [
290+
['propertyInTraitPrimitiveType',newType(Type::BUILTIN_TYPE_STRING)],
291+
['propertyInTraitObjectSameNamespace',newType(Type::BUILTIN_TYPE_OBJECT,false, DummyUsedInTrait::class)],
292+
['propertyInTraitObjectDifferentNamespace',newType(Type::BUILTIN_TYPE_OBJECT,false, Dummy::class)],
293+
];
294+
}
295+
276296
protectedfunctionisPhpDocumentorV5()
277297
{
278298
if (class_exists(InvalidTag::class)) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
namespaceSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
13+
14+
useSymfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
15+
16+
trait DummyTrait
17+
{
18+
/**
19+
* @var string
20+
*/
21+
private$propertyInTraitPrimitiveType;
22+
23+
/**
24+
* @var DummyUsedInTrait
25+
*/
26+
private$propertyInTraitObjectSameNamespace;
27+
28+
/**
29+
* @var Dummy
30+
*/
31+
private$propertyInTraitObjectDifferentNamespace;
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
namespaceSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
13+
14+
class DummyUsedInTrait
15+
{
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
namespaceSymfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
13+
14+
class DummyUsingTrait
15+
{
16+
use DummyTrait;
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp