diff --git a/src/Node/MethodDeclaration.php b/src/Node/MethodDeclaration.php index 545c8d22..e9bddb45 100644 --- a/src/Node/MethodDeclaration.php +++ b/src/Node/MethodDeclaration.php @@ -40,18 +40,38 @@ class MethodDeclaration extends Node implements FunctionLike { // FunctionBody 'compoundStatementOrSemicolon' ]; + + public function hasModifier(int $targetModifier) : bool { + if ($this->modifiers === null) { + return false; + } + foreach ($this->modifiers as $modifier) { + if ($modifier->kind === $targetModifier) { + return true; + } + } + return false; + } public function isStatic() : bool { - if ($this->modifiers === null) { - return false; - } - foreach ($this->modifiers as $modifier) { - if ($modifier->kind === TokenKind::StaticKeyword) { - return true; - } - } - return false; + return $this->hasModifier(TokenKind::StaticKeyword); } + + public function isPublic() : bool { + return $this->hasModifier(TokenKind::PublicKeyword); + } + + public function isProtected() : bool { + return $this->hasModifier(TokenKind::ProtectedKeyword); + } + + public function isPrivate() : bool { + return $this->hasModifier(TokenKind::PrivateKeyword); + } + + public function isAbstract() : bool { + return $this->hasModifier(TokenKind::AbstractKeyword); + } public function getName() { return $this->name->getText($this->getFileContents());