Skip to content

Commit

Permalink
#24 For PHP version >= 7.4.0 look for the properties explicit type de…
Browse files Browse the repository at this point in the history
…claration first (#25)

* #24 For PHP version >= 7.4.0 look for the properties explicit type declaration first

* Apply suggestions from code review

Co-authored-by: Pavel Alexeev <Pavel_Alexeev@epam.com>
Co-authored-by: Nick <nickjobszh@gmail.com>
  • Loading branch information
3 people committed Dec 8, 2021
1 parent 0d6e73b commit 0fe7667
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Parser/TokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,18 @@ public function getProperties(string $classPath): array
*/
public function getPropertyClass(ReflectionProperty $property, bool $ignorePrimitive = true)
{
// Get the content of the @var annotation
if (preg_match('/@var\s+([^\s]+)/', (string) $property->getDocComment(), $matches)) {
list(, $type) = $matches;
} else {
return null;
$type = null;
// Get is explicit type decralation if possible
if (version_compare(phpversion(), '7.4.0', '>=') && null !== $property->getType()) {
$type = $property->getType()->getName();
}

if (is_null($type)) { // Try get the content of the @var annotation
if (preg_match('/@var\s+([^\s]+)/', (string) $property->getDocComment(), $matches)) {
list(, $type) = $matches;
} else {
return null;
}
}

$types = explode('|', $this->replaceTypeStrings($type));
Expand Down

0 comments on commit 0fe7667

Please sign in to comment.