mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-16 14:48:32 +01:00
Promoted properties with hooks do not need visibility modifier
This commit is contained in:
parent
469377f4a8
commit
4f9dc8b0f5
@ -68,11 +68,20 @@ class Param extends NodeAbstract {
|
||||
* Whether this parameter uses constructor property promotion.
|
||||
*/
|
||||
public function isPromoted(): bool {
|
||||
return $this->flags !== 0;
|
||||
return $this->flags !== 0 || $this->hooks !== [];
|
||||
}
|
||||
|
||||
public function isPublic(): bool {
|
||||
return (bool) ($this->flags & Modifiers::PUBLIC);
|
||||
$public = (bool) ($this->flags & Modifiers::PUBLIC);
|
||||
if ($public) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hooks === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($this->flags & Modifiers::VISIBILITY_MASK) === 0;
|
||||
}
|
||||
|
||||
public function isProtected(): bool {
|
||||
|
@ -47,4 +47,18 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
|
||||
$node->flags = Modifiers::PUBLIC_SET;
|
||||
$this->assertTrue($node->isPublicSet());
|
||||
}
|
||||
|
||||
public function testPromotedPropertyWithoutVisibilityModifier(): void {
|
||||
$node = new Param(new Variable('foo'));
|
||||
$get = new PropertyHook('get', null);
|
||||
$node->hooks[] = $get;
|
||||
|
||||
$this->assertTrue($node->isPromoted());
|
||||
$this->assertTrue($node->isPublic());
|
||||
}
|
||||
|
||||
public function testNonPromotedPropertyIsNotPublic(): void {
|
||||
$node = new Param(new Variable('foo'));
|
||||
$this->assertFalse($node->isPublic());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user