550b54ba2dee53973a8dcd5f24a5f96c2607583d
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Node / Stmt / ClassMethod.php
1 <?php declare(strict_types=1);
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 Node\Identifier Name */
15     public $name;
16     /** @var Node\Param[] Parameters */
17     public $params;
18     /** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
19     public $returnType;
20     /** @var Node\Stmt[]|null Statements */
21     public $stmts;
22
23     private static $magicNames = [
24         '__construct'  => true,
25         '__destruct'   => true,
26         '__call'       => true,
27         '__callstatic' => true,
28         '__get'        => true,
29         '__set'        => true,
30         '__isset'      => true,
31         '__unset'      => true,
32         '__sleep'      => true,
33         '__wakeup'     => true,
34         '__tostring'   => true,
35         '__set_state'  => true,
36         '__clone'      => true,
37         '__invoke'     => true,
38         '__debuginfo'  => true,
39     ];
40
41     /**
42      * Constructs a class method node.
43      *
44      * @param string|Node\Identifier $name Name
45      * @param array $subNodes   Array of the following optional subnodes:
46      *                          'flags       => MODIFIER_PUBLIC: Flags
47      *                          'byRef'      => false          : Whether to return by reference
48      *                          'params'     => array()        : Parameters
49      *                          'returnType' => null           : Return type
50      *                          'stmts'      => array()        : Statements
51      * @param array $attributes Additional attributes
52      */
53     public function __construct($name, array $subNodes = [], array $attributes = []) {
54         parent::__construct($attributes);
55         $this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
56         $this->byRef = $subNodes['byRef'] ?? false;
57         $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
58         $this->params = $subNodes['params'] ?? [];
59         $returnType = $subNodes['returnType'] ?? null;
60         $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
61         $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : [];
62     }
63
64     public function getSubNodeNames() : array {
65         return ['flags', 'byRef', 'name', 'params', 'returnType', 'stmts'];
66     }
67
68     public function returnsByRef() : bool {
69         return $this->byRef;
70     }
71
72     public function getParams() : array {
73         return $this->params;
74     }
75
76     public function getReturnType() {
77         return $this->returnType;
78     }
79
80     public function getStmts() {
81         return $this->stmts;
82     }
83
84     /**
85      * Whether the method is explicitly or implicitly public.
86      *
87      * @return bool
88      */
89     public function isPublic() : bool {
90         return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
91             || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
92     }
93
94     /**
95      * Whether the method is protected.
96      *
97      * @return bool
98      */
99     public function isProtected() : bool {
100         return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
101     }
102
103     /**
104      * Whether the method is private.
105      *
106      * @return bool
107      */
108     public function isPrivate() : bool {
109         return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
110     }
111
112     /**
113      * Whether the method is abstract.
114      *
115      * @return bool
116      */
117     public function isAbstract() : bool {
118         return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT);
119     }
120
121     /**
122      * Whether the method is final.
123      * 
124      * @return bool
125      */
126     public function isFinal() : bool {
127         return (bool) ($this->flags & Class_::MODIFIER_FINAL);
128     }
129
130     /**
131      * Whether the method is static.
132      *
133      * @return bool
134      */
135     public function isStatic() : bool {
136         return (bool) ($this->flags & Class_::MODIFIER_STATIC);
137     }
138
139     /**
140      * Whether the method is magic.
141      *
142      * @return bool
143      */
144     public function isMagic() : bool {
145         return isset(self::$magicNames[$this->name->toLowerString()]);
146     }
147     
148     public function getType() : string {
149         return 'Stmt_ClassMethod';
150     }
151 }