mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-16 22:58:15 +01:00
Add PropertyHook::isFinal()
helper method with tests
This commit is contained in:
parent
f43324a074
commit
f212bb7afb
@ -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)];
|
||||
|
34
test/PhpParser/Node/PropertyHookTest.php
Normal file
34
test/PhpParser/Node/PropertyHookTest.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user