Add PropertyHook::isFinal() helper method with tests

This commit is contained in:
Ondrej Mirtes 2024-12-11 11:04:44 +01:00 committed by Nikita Popov
parent f43324a074
commit f212bb7afb
2 changed files with 42 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace PhpParser\Node;
use PhpParser\Modifiers;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeAbstract;
@ -58,6 +59,13 @@ class PropertyHook extends NodeAbstract implements FunctionLike {
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)];

View File

@ -0,0 +1,34 @@
<?php declare(strict_types=1);
namespace PhpParser\Node;
use PhpParser\Modifiers;
class PropertyHookTest extends \PHPUnit\Framework\TestCase {
/**
* @dataProvider provideModifiers
*/
public function testModifiers($modifier): void {
$node = new PropertyHook(
'get',
null,
[
'flags' => 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'],
];
}
}