diff --git a/lib/PhpParser/Node/PropertyHook.php b/lib/PhpParser/Node/PropertyHook.php index 9ae77a2b6e..fab0e9d39a 100644 --- a/lib/PhpParser/Node/PropertyHook.php +++ b/lib/PhpParser/Node/PropertyHook.php @@ -2,6 +2,7 @@ namespace PhpParser\Node; +use PhpParser\Modifiers; use PhpParser\Node\Stmt\Return_; use PhpParser\NodeAbstract; @@ -58,6 +59,13 @@ public function getReturnType() { return null; } + /** + * Whether the property hook is final. + */ + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); + } + public function getStmts(): ?array { if ($this->body instanceof Expr) { return [new Return_($this->body)]; diff --git a/test/PhpParser/Node/PropertyHookTest.php b/test/PhpParser/Node/PropertyHookTest.php new file mode 100644 index 0000000000..c8bd07cffb --- /dev/null +++ b/test/PhpParser/Node/PropertyHookTest.php @@ -0,0 +1,34 @@ + constant(Modifiers::class . '::' . strtoupper($modifier)), + ] + ); + + $this->assertTrue($node->{'is' . $modifier}()); + } + + public function testNoModifiers(): void { + $node = new PropertyHook('get', null); + + $this->assertFalse($node->isFinal()); + } + + public static function provideModifiers() { + return [ + ['final'], + ]; + } +}