Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace PhpParser\Node\Stmt;
|
Chris@0
|
4
|
Chris@0
|
5 use PhpParser\Node;
|
Chris@0
|
6 use PhpParser\Node\FunctionLike;
|
Chris@0
|
7
|
Chris@0
|
8 class ClassMethod extends Node\Stmt implements FunctionLike
|
Chris@0
|
9 {
|
Chris@0
|
10 /** @var int Flags */
|
Chris@0
|
11 public $flags;
|
Chris@0
|
12 /** @var bool Whether to return by reference */
|
Chris@0
|
13 public $byRef;
|
Chris@0
|
14 /** @var string Name */
|
Chris@0
|
15 public $name;
|
Chris@0
|
16 /** @var Node\Param[] Parameters */
|
Chris@0
|
17 public $params;
|
Chris@0
|
18 /** @var null|string|Node\Name|Node\NullableType Return type */
|
Chris@0
|
19 public $returnType;
|
Chris@0
|
20 /** @var Node[]|null Statements */
|
Chris@0
|
21 public $stmts;
|
Chris@0
|
22
|
Chris@0
|
23 /** @deprecated Use $flags instead */
|
Chris@0
|
24 public $type;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Constructs a class method node.
|
Chris@0
|
28 *
|
Chris@0
|
29 * @param string $name Name
|
Chris@0
|
30 * @param array $subNodes Array of the following optional subnodes:
|
Chris@0
|
31 * 'flags => MODIFIER_PUBLIC: Flags
|
Chris@0
|
32 * 'byRef' => false : Whether to return by reference
|
Chris@0
|
33 * 'params' => array() : Parameters
|
Chris@0
|
34 * 'returnType' => null : Return type
|
Chris@0
|
35 * 'stmts' => array() : Statements
|
Chris@0
|
36 * @param array $attributes Additional attributes
|
Chris@0
|
37 */
|
Chris@0
|
38 public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
Chris@0
|
39 parent::__construct($attributes);
|
Chris@0
|
40 $this->flags = isset($subNodes['flags']) ? $subNodes['flags']
|
Chris@0
|
41 : (isset($subNodes['type']) ? $subNodes['type'] : 0);
|
Chris@0
|
42 $this->type = $this->flags;
|
Chris@0
|
43 $this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
Chris@0
|
44 $this->name = $name;
|
Chris@0
|
45 $this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
Chris@0
|
46 $this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
Chris@0
|
47 $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 public function getSubNodeNames() {
|
Chris@0
|
51 return array('flags', 'byRef', 'name', 'params', 'returnType', 'stmts');
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 public function returnsByRef() {
|
Chris@0
|
55 return $this->byRef;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 public function getParams() {
|
Chris@0
|
59 return $this->params;
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 public function getReturnType() {
|
Chris@0
|
63 return $this->returnType;
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@0
|
66 public function getStmts() {
|
Chris@0
|
67 return $this->stmts;
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 public function isPublic() {
|
Chris@0
|
71 return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
|
Chris@0
|
72 || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
|
Chris@0
|
73 }
|
Chris@0
|
74
|
Chris@0
|
75 public function isProtected() {
|
Chris@0
|
76 return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 public function isPrivate() {
|
Chris@0
|
80 return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 public function isAbstract() {
|
Chris@0
|
84 return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 public function isFinal() {
|
Chris@0
|
88 return (bool) ($this->flags & Class_::MODIFIER_FINAL);
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 public function isStatic() {
|
Chris@0
|
92 return (bool) ($this->flags & Class_::MODIFIER_STATIC);
|
Chris@0
|
93 }
|
Chris@0
|
94 }
|