Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/PropertyInfo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

6.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ private function getDocBlock(string $class, string $property): array

$ucFirstProperty = ucfirst($property);

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

/**
* @return array{PhpDocNode, string}|null
* @return array{PhpDocNode, int, string}|null
*/
private function getDocBlockFromProperty(string $class, string $property): ?array
{
Expand All @@ -221,15 +221,21 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra
return null;
}

if (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) {
$source = self::PROPERTY;

if ($reflectionProperty->isPromoted()) {
$constructor = new \ReflectionMethod($class, '__construct');
$rawDocNode = $constructor->getDocComment();
$source = self::MUTATOR;
} elseif (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) {
return null;
}

$tokens = new TokenIterator($this->lexer->tokenize($rawDocNode));
$phpDocNode = $this->phpDocParser->parse($tokens);
$tokens->consumeTokenType(Lexer::TOKEN_END);

return [$phpDocNode, $reflectionProperty->class];
return [$phpDocNode, $source, $reflectionProperty->class];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\PropertyInfo\Tests\Fixtures\DefaultValue;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem;
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait;
Expand Down Expand Up @@ -434,6 +435,21 @@ public function testDummyNamespaceWithProperty()
$this->assertEquals('A\Property', $phpStanTypes[0]->getClassName());
$this->assertEquals($phpDocTypes[0]->getClassName(), $phpStanTypes[0]->getClassName());
}

/**
* @dataProvider php80TypesProvider
*/
public function testExtractPhp80Type($property, array $type = null)
{
$this->assertEquals($type, $this->extractor->getTypes(Php80Dummy::class, $property, []));
}

public function php80TypesProvider()
{
return [
['promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]],
];
}
}

class PhpStanOmittedParamTagTypeDocBlock
Expand Down