Skip to content

Commit

Permalink
Add ReflectionProperty::getType() and hasType()
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Apr 6, 2021
1 parent 6851b5c commit 3839970
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11564,6 +11564,7 @@
'ReflectionProperty::getName' => ['string'],
'ReflectionProperty::getType' => ['?ReflectionType'],
'ReflectionProperty::getValue' => ['mixed', 'object='=>'object'],
'ReflectionProperty::hasType' => ['bool'],
'ReflectionProperty::isDefault' => ['bool'],
'ReflectionProperty::isPrivate' => ['bool'],
'ReflectionProperty::isProtected' => ['bool'],
Expand Down
11 changes: 11 additions & 0 deletions stubs/Reflection.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ class ReflectionProperty implements Reflector
* @return array<ReflectionAttribute<TClass>>
*/
public function getAttributes(?string $name = null, int $flags = 0): array {}

/**
* @since 7.4
* @psalm-assert-if-true ReflectionType $this->getType()
*/
public function hasType() : bool {}

/**
* @since 7.4
*/
public function getType() : ?ReflectionType {}
}

class ReflectionMethod implements Reflector
Expand Down
10 changes: 10 additions & 0 deletions tests/AssertAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,16 @@ function foo(array $foos) : array {
*/
function allIsInstanceOf($value, $class): void {}'
],
'implicitReflectionPropertyAssertion' => [
'<?php
$method = new ReflectionClass(stdClass::class);
$properties = $method->getProperties();
foreach ($properties as $property) {
if ($property->hasType()) {
$property->getType()->__toString();
}
}',
],
];
}

Expand Down

0 comments on commit 3839970

Please sign in to comment.