3 namespace PhpParser\Node\Stmt;
6 use PhpParser\Node\FunctionLike;
8 class ClassMethod extends Node\Stmt implements FunctionLike
12 /** @var bool Whether to return by reference */
14 /** @var string Name */
16 /** @var Node\Param[] Parameters */
18 /** @var null|string|Node\Name|Node\NullableType Return type */
20 /** @var Node[] Statements */
23 /** @deprecated Use $flags instead */
27 * Constructs a class method node.
29 * @param string $name Name
30 * @param array $subNodes Array of the following optional subnodes:
31 * 'flags => MODIFIER_PUBLIC: Flags
32 * 'byRef' => false : Whether to return by reference
33 * 'params' => array() : Parameters
34 * 'returnType' => null : Return type
35 * 'stmts' => array() : Statements
36 * @param array $attributes Additional attributes
38 public function __construct($name, array $subNodes = array(), array $attributes = array()) {
39 parent::__construct($attributes);
40 $this->flags = isset($subNodes['flags']) ? $subNodes['flags']
41 : (isset($subNodes['type']) ? $subNodes['type'] : 0);
42 $this->type = $this->flags;
43 $this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
45 $this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
46 $this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
47 $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
50 public function getSubNodeNames() {
51 return array('flags', 'byRef', 'name', 'params', 'returnType', 'stmts');
54 public function returnsByRef() {
58 public function getParams() {
62 public function getReturnType() {
63 return $this->returnType;
66 public function getStmts() {
70 public function isPublic() {
71 return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
72 || ($this->flags & Class_::VISIBILITY_MODIFER_MASK) === 0;
75 public function isProtected() {
76 return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
79 public function isPrivate() {
80 return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
83 public function isAbstract() {
84 return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
87 public function isFinal() {
88 return (bool) ($this->flags & Class_::MODIFIER_FINAL);
91 public function isStatic() {
92 return (bool) ($this->flags & Class_::MODIFIER_STATIC);