1 | <?php |
||
21 | class MethodMetadata |
||
22 | { |
||
23 | const PRIVATE = 'private'; |
||
24 | const PUBLIC = 'public'; |
||
25 | const PROTECTED = 'protected'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $abstract; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $final; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $visibility; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | private $returnType; |
||
51 | |||
52 | /** |
||
53 | * @var bool |
||
54 | */ |
||
55 | private $byRef; |
||
56 | |||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $static; |
||
61 | |||
62 | /** |
||
63 | * @var ParameterMetadata[] |
||
64 | */ |
||
65 | private $parameters; |
||
66 | |||
67 | /** |
||
68 | * @var \PhpParser\Node\Stmt\ClassMethod |
||
69 | */ |
||
70 | private $ast; |
||
71 | |||
72 | /** |
||
73 | * MethodMetadata constructor. |
||
74 | * |
||
75 | * @param string $name |
||
76 | * @param bool $abstract |
||
77 | * @param bool $final |
||
78 | * @param string $visibility |
||
79 | * @param string $returnType |
||
80 | * @param bool $byRef |
||
81 | * @param bool $static |
||
82 | * @param ParameterMetadata[] $parameters |
||
83 | * @param \PhpParser\Node\Stmt\ClassMethod|null $ast |
||
84 | */ |
||
85 | 1 | public function __construct($name, $abstract = false, $final = false, $visibility = self::PUBLIC, $returnType = null, $byRef = false, $static = false, array $parameters = [], Stmt\ClassMethod $ast = null) |
|
86 | { |
||
87 | 1 | $this->name = $name; |
|
88 | 1 | $this->abstract = $abstract; |
|
89 | 1 | $this->final = $final; |
|
90 | 1 | $this->visibility = $visibility; |
|
91 | 1 | $this->returnType = $returnType; |
|
92 | 1 | $this->byRef = $byRef; |
|
93 | 1 | $this->static = $static; |
|
94 | 1 | $this->parameters = $parameters; |
|
95 | 1 | $this->ast = $ast; |
|
96 | 1 | } |
|
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | 1 | public function getName() |
|
102 | { |
||
103 | 1 | return $this->name; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function isAbstract() |
||
113 | |||
114 | /** |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function isFinal() |
||
121 | |||
122 | /** |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getVisibility() |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getReturnType() |
||
137 | |||
138 | /** |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function byReference() |
||
145 | |||
146 | /** |
||
147 | * @return bool |
||
148 | */ |
||
149 | public function isStatic() |
||
153 | |||
154 | /** |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function hasParameters() |
||
161 | |||
162 | /** |
||
163 | * @return ParameterMetadata[] |
||
164 | */ |
||
165 | 1 | public function getParameters() |
|
166 | { |
||
167 | 1 | return $this->parameters; |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Check if method is constructor. |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function isConstructor() |
||
179 | |||
180 | /** |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function isPrivate() |
||
187 | |||
188 | /** |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function isProtected() |
||
195 | |||
196 | /** |
||
197 | * @return bool |
||
198 | */ |
||
199 | 1 | public function isPublic() |
|
200 | { |
||
201 | 1 | return $this->visibility === self::PUBLIC; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * @return \PhpParser\Node\Stmt\ClassMethod |
||
206 | */ |
||
207 | public function getAst() |
||
211 | |||
212 | /** |
||
213 | * Create method metadata instance from \PhpParser\Node\Stmt\ClassMethod |
||
214 | * |
||
215 | * @param \PhpParser\Node\Stmt\ClassMethod $method |
||
216 | * @return MethodMetadata|static |
||
217 | */ |
||
218 | public static function fromClassMethod(Stmt\ClassMethod $method) |
||
241 | } |
||
242 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.