Skip to content

Commit 1a9118b

Browse files
committed
Add more modifier checks to MethodDeclaration node
1 parent 6c701e3 commit 1a9118b

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/Node/MethodDeclaration.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,38 @@ class MethodDeclaration extends Node implements FunctionLike {
4040
// FunctionBody
4141
'compoundStatementOrSemicolon'
4242
];
43+
44+
public function hasModifier(int $targetModifier) : bool {
45+
if ($this->modifiers === null) {
46+
return false;
47+
}
48+
foreach ($this->modifiers as $modifier) {
49+
if ($modifier->kind === $targetModifier) {
50+
return true;
51+
}
52+
}
53+
return false;
54+
}
4355

4456
public function isStatic() : bool {
45-
if ($this->modifiers === null) {
46-
return false;
47-
}
48-
foreach ($this->modifiers as $modifier) {
49-
if ($modifier->kind === TokenKind::StaticKeyword) {
50-
return true;
51-
}
52-
}
53-
return false;
57+
return $this->hasModifier(TokenKind::StaticKeyword);
5458
}
59+
60+
public function isPublic() : bool {
61+
return $this->hasModifier(TokenKind::PublicKeyword);
62+
}
63+
64+
public function isProtected() : bool {
65+
return $this->hasModifier(TokenKind::ProtectedKeyword);
66+
}
67+
68+
public function isPrivate() : bool {
69+
return $this->hasModifier(TokenKind::PrivateKeyword);
70+
}
71+
72+
public function isAbstract() : bool {
73+
return $this->hasModifier(TokenKind::AbstractKeyword);
74+
}
5575

5676
public function getName() {
5777
return $this->name->getText($this->getFileContents());

0 commit comments

Comments
 (0)