6391c41d1796daaf65fe9dfe433d9e248b120ec9
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Node / Stmt / ClassMethod.php
1 <?php
2
3 namespace PhpParser\Node\Stmt;
4
5 use PhpParser\Node;
6 use PhpParser\Node\FunctionLike;
7
8 class ClassMethod extends Node\Stmt implements FunctionLike
9 {
10     /** @var int Flags */
11     public $flags;
12     /** @var bool Whether to return by reference */
13     public $byRef;
14     /** @var string Name */
15     public $name;
16     /** @var Node\Param[] Parameters */
17     public $params;
18     /** @var null|string|Node\Name|Node\NullableType Return type */
19     public $returnType;
20     /** @var Node[] Statements */
21     public $stmts;
22
23     /** @deprecated Use $flags instead */
24     public $type;
25
26     /**
27      * Constructs a class method node.
28      *
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
37      */
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;
44         $this->name = $name;
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();
48     }
49
50     public function getSubNodeNames() {
51         return array('flags', 'byRef', 'name', 'params', 'returnType', 'stmts');
52     }
53
54     public function returnsByRef() {
55         return $this->byRef;
56     }
57
58     public function getParams() {
59         return $this->params;
60     }
61
62     public function getReturnType() {
63         return $this->returnType;
64     }
65
66     public function getStmts() {
67         return $this->stmts;
68     }
69
70     public function isPublic() {
71         return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
72             || ($this->flags & Class_::VISIBILITY_MODIFER_MASK) === 0;
73     }
74
75     public function isProtected() {
76         return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
77     }
78
79     public function isPrivate() {
80         return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
81     }
82
83     public function isAbstract() {
84         return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
85     }
86
87     public function isFinal() {
88         return (bool) ($this->flags & Class_::MODIFIER_FINAL);
89     }
90
91     public function isStatic() {
92         return (bool) ($this->flags & Class_::MODIFIER_STATIC);
93     }
94 }