Skip to content

Commit a7aad04

Browse files
authored
Merge pull request #68 from svandervlugt/types
Support nullable type declarations
2 parents 9f108b2 + 05c935e commit a7aad04

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/Reflection/ReflectionClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ public function getProperties(): array
316316
// otherwise final private $foo would be parsed and private final $bar
317317
// would not be parsed.
318318
//
319-
// Skip T_STRING because if it exists, it must contain a type declaration.
320-
$var_loc = $tokens->next($vis_loc, [T_COMMENT, T_WHITESPACE, T_STATIC, T_FINAL, T_STRING]);
319+
// Skip T_STRING and "?" because if it exists, it must be a type declaration.
320+
$var_loc = $tokens->next($vis_loc, [T_COMMENT, T_WHITESPACE, T_STATIC, T_FINAL, T_STRING, '?']);
321321
if ($tokens->type($var_loc) !== T_VARIABLE) {
322322
continue;
323323
}

test/Reflection/ReflectionClassTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function fileProvider(): array
111111
'public $nerf;',
112112
'private $riet;',
113113
'private $touw;',
114+
'private $sap;',
114115
],
115116
],
116117
[
@@ -239,7 +240,7 @@ public function testClassNotFoundException(): void
239240
$class = new ReflectionClass(__DIR__ . '/fixtures/no_class.php');
240241
self::assertEquals('ThisNamespace', $class->getNamespace());
241242

242-
self::expectException(ClassDefinitionNotFoundException::class);
243+
$this->expectException(ClassDefinitionNotFoundException::class);
243244

244245
$class->getName();
245246
}
@@ -249,7 +250,7 @@ public function testEmptyFileClassNotFoundException(): void
249250
$class = new ReflectionClass(__DIR__ . '/fixtures/empty.php');
250251
self::assertEquals('', $class->getNamespace());
251252

252-
self::expectException(ClassDefinitionNotFoundException::class);
253+
$this->expectException(ClassDefinitionNotFoundException::class);
253254

254255
$class->getName();
255256
}
@@ -258,7 +259,7 @@ public function testBroken(): void
258259
{
259260
$class = new ReflectionClass(__DIR__ . '/fixtures/broken.php');
260261

261-
self::expectException(ClassDefinitionNotFoundException::class);
262+
$this->expectException(ClassDefinitionNotFoundException::class);
262263

263264
$class->getUseStatements();
264265
}

test/Reflection/fixtures/modifiers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ class Boom {
1919
var $nerf;
2020
public static private final protected private $riet;
2121
private string $touw;
22-
}
22+
private ?int $sap;
23+
}

0 commit comments

Comments
 (0)