Skip to content

Commit 1a38206

Browse files
authored
Merge pull request #2 from phan/property-hook-modifiers
Add property hook modifiers
2 parents 842702a + 174e070 commit 1a38206

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Node/PropertyHook.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
namespace Microsoft\PhpParser\Node;
88

9+
use Microsoft\PhpParser\ModifiedTypeInterface;
10+
use Microsoft\PhpParser\ModifiedTypeTrait;
911
use Microsoft\PhpParser\Node;
1012
use Microsoft\PhpParser\Node\DelimitedList\ParameterDeclarationList;
1113
use Microsoft\PhpParser\Node\Statement\CompoundStatementNode;
1214
use Microsoft\PhpParser\Token;
1315

14-
class PropertyHook extends Node {
16+
class PropertyHook extends Node implements ModifiedTypeInterface {
17+
use ModifiedTypeTrait;
1518
/** @var AttributeGroup[]|null */
1619
public $attributes;
1720

@@ -41,6 +44,7 @@ class PropertyHook extends Node {
4144

4245
const CHILD_NAMES = [
4346
'attributes',
47+
'modifiers',
4448
'hookKeyword',
4549
'openParen',
4650
'parameterList',

src/Parser.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,30 @@ private function parseModifiers(): array {
16141614
return $modifiers;
16151615
}
16161616

1617+
/**
1618+
* Parse modifiers that are allowed on property hooks (visibility, static, final).
1619+
*
1620+
* @return Token[]
1621+
*/
1622+
private function parsePropertyHookModifiers(): array {
1623+
$modifiers = [];
1624+
while (true) {
1625+
$token = $this->getCurrentToken();
1626+
switch ($token->kind) {
1627+
case TokenKind::PublicKeyword:
1628+
case TokenKind::ProtectedKeyword:
1629+
case TokenKind::PrivateKeyword:
1630+
case TokenKind::StaticKeyword:
1631+
case TokenKind::FinalKeyword:
1632+
$modifiers[] = $token;
1633+
$this->advanceToken();
1634+
continue 2;
1635+
}
1636+
break;
1637+
}
1638+
return $modifiers;
1639+
}
1640+
16171641
private function isParameterStartFn() {
16181642
return function ($token) {
16191643
switch ($token->kind) {
@@ -3527,6 +3551,8 @@ private function parsePropertyHook(PropertyHookList $parentNode): ?PropertyHook
35273551
$hook->attributes = $this->parseAttributeGroups($hook);
35283552
}
35293553

3554+
$hook->modifiers = $this->parsePropertyHookModifiers();
3555+
35303556
$token = $this->getCurrentToken();
35313557
if ($token->kind === TokenKind::Name) {
35323558
$text = \strtolower(\trim($token->getText($this->sourceFile->fileContents)));

0 commit comments

Comments
 (0)