Thanks to visit codestin.com
Credit goes to github.com

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
9 changes: 9 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<!-- Class has been added in PHP 8.1 -->
<referencedClass name="ReflectionIntersectionType"/>
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ private function extractFromReflectionType(\ReflectionType $reflectionType, \Ref
$types = [];
$nullable = $reflectionType->allowsNull();

foreach ($reflectionType instanceof \ReflectionUnionType ? $reflectionType->getTypes() : [$reflectionType] as $type) {
$phpTypeOrClass = $reflectionType instanceof \ReflectionNamedType ? $reflectionType->getName() : (string) $type;
foreach (($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) ? $reflectionType->getTypes() : [$reflectionType] as $type) {
$phpTypeOrClass = $type->getName();
if ('null' === $phpTypeOrClass || 'mixed' === $phpTypeOrClass || 'never' === $phpTypeOrClass) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,20 @@ public function php80TypesProvider()
}

/**
* @dataProvider php81TypesProvider
* @requires PHP 8.1
*/
public function testExtractPhp81Type()
public function testExtractPhp81Type($property, array $type = null)
{
$this->assertNull($this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy', 'nothing', []));
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php81Dummy', $property, []));
}

public function php81TypesProvider()
{
return [
['nothing', null],
['collection', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Traversable'), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Countable')]],
Copy link
Contributor

@ro0NL ro0NL Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tend to believe the intersection type should be preserved as a single type;

[new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Traversable&Countable')]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe on a higher branch, since this PR is motivated by the need to generate a proper message.
Follow up welcome.

];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public function getNothing(): never
{
throw new \Exception('Oops');
}

public function getCollection(): \Traversable&\Countable
{
}
}