Skip to content

Commit 639c4a4

Browse files
authored
fix stan (php-kafka#27)
1 parent 0fe7667 commit 639c4a4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Parser/TokenParser.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PhpKafka\PhpAvroSchemaGenerator\Parser;
66

7+
use ReflectionUnionType;
8+
use ReflectionNamedType;
79
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassProperty;
810
use ReflectionClass;
911
use ReflectionProperty;
@@ -200,9 +202,14 @@ public function getProperties(string $classPath): array
200202
public function getPropertyClass(ReflectionProperty $property, bool $ignorePrimitive = true)
201203
{
202204
$type = null;
205+
$phpVersion = false === phpversion() ? '7.0.0' : phpversion();
203206
// Get is explicit type decralation if possible
204-
if (version_compare(phpversion(), '7.4.0', '>=') && null !== $property->getType()) {
205-
$type = $property->getType()->getName();
207+
if (version_compare($phpVersion, '7.4.0', '>=') && null !== $property->getType()) {
208+
$reflectionType = $property->getType();
209+
210+
if ($reflectionType instanceof ReflectionNamedType) {
211+
$type = $reflectionType->getName();
212+
}
206213
}
207214

208215
if (is_null($type)) { // Try get the content of the @var annotation

0 commit comments

Comments
 (0)