Skip to content

Commit f212bb7

Browse files
ondrejmirtesnikic
authored andcommitted
Add PropertyHook::isFinal() helper method with tests
1 parent f43324a commit f212bb7

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/PhpParser/Node/PropertyHook.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpParser\Node;
44

5+
use PhpParser\Modifiers;
56
use PhpParser\Node\Stmt\Return_;
67
use PhpParser\NodeAbstract;
78

@@ -58,6 +59,13 @@ public function getReturnType() {
5859
return null;
5960
}
6061

62+
/**
63+
* Whether the property hook is final.
64+
*/
65+
public function isFinal(): bool {
66+
return (bool) ($this->flags & Modifiers::FINAL);
67+
}
68+
6169
public function getStmts(): ?array {
6270
if ($this->body instanceof Expr) {
6371
return [new Return_($this->body)];
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpParser\Node;
4+
5+
use PhpParser\Modifiers;
6+
7+
class PropertyHookTest extends \PHPUnit\Framework\TestCase {
8+
/**
9+
* @dataProvider provideModifiers
10+
*/
11+
public function testModifiers($modifier): void {
12+
$node = new PropertyHook(
13+
'get',
14+
null,
15+
[
16+
'flags' => constant(Modifiers::class . '::' . strtoupper($modifier)),
17+
]
18+
);
19+
20+
$this->assertTrue($node->{'is' . $modifier}());
21+
}
22+
23+
public function testNoModifiers(): void {
24+
$node = new PropertyHook('get', null);
25+
26+
$this->assertFalse($node->isFinal());
27+
}
28+
29+
public static function provideModifiers() {
30+
return [
31+
['final'],
32+
];
33+
}
34+
}

0 commit comments

Comments
 (0)