Promoted properties with hooks do not need visibility modifier

This commit is contained in:
Ondrej Mirtes 2024-12-11 09:37:29 +01:00 committed by Nikita Popov
parent 469377f4a8
commit 4f9dc8b0f5
2 changed files with 25 additions and 2 deletions

View File

@ -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 {

View File

@ -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());
}
}