1 | <?php |
||
29 | abstract class AbstractPhpStruct extends AbstractModel implements NamespaceInterface, DocblockInterface { |
||
30 | |||
31 | use QualifiedNameTrait; |
||
32 | use DocblockTrait; |
||
33 | use LongDescriptionTrait; |
||
34 | |||
35 | protected static $phpParser; |
||
36 | |||
37 | private $useStatements = []; |
||
38 | |||
39 | private $requiredFiles = []; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * @var PhpMethod[] |
||
44 | */ |
||
45 | private $methods = []; |
||
46 | |||
47 | /** |
||
48 | * Creates a new struct |
||
49 | * |
||
50 | * @param string $name the fqcn |
||
51 | * @return static |
||
52 | */ |
||
53 | 10 | public static function create($name = null) { |
|
56 | |||
57 | /** |
||
58 | * |
||
59 | * @return PhpMethod |
||
60 | */ |
||
61 | 5 | protected static function createMethod(\ReflectionMethod $method) { |
|
64 | |||
65 | /** |
||
66 | * |
||
67 | * @return PhpProperty |
||
68 | */ |
||
69 | 4 | protected static function createProperty(\ReflectionProperty $property) { |
|
72 | |||
73 | /** |
||
74 | * Creates a new struct |
||
75 | * |
||
76 | * @param string $name the fqcn |
||
77 | */ |
||
78 | 51 | public function __construct($name = null) { |
|
82 | |||
83 | /** |
||
84 | * Sets requried files |
||
85 | * |
||
86 | * @param array $files |
||
87 | * @return $this |
||
88 | */ |
||
89 | 1 | public function setRequiredFiles(array $files) { |
|
94 | |||
95 | /** |
||
96 | * Adds a new required file |
||
97 | * |
||
98 | * @param string $file |
||
99 | * @return $this |
||
100 | */ |
||
101 | 1 | public function addRequiredFile($file) { |
|
106 | |||
107 | /** |
||
108 | * Returns required files |
||
109 | * |
||
110 | * @return array collection of filenames |
||
111 | */ |
||
112 | 14 | public function getRequiredFiles() { |
|
115 | |||
116 | /** |
||
117 | * Sets use statements |
||
118 | * |
||
119 | * @see #addUseStatement |
||
120 | * @see #declareUses() |
||
121 | * @param array $useStatements |
||
122 | * @return $this |
||
123 | */ |
||
124 | 19 | public function setUseStatements(array $useStatements) { |
|
132 | |||
133 | /** |
||
134 | * Adds a use statement with an optional alias |
||
135 | * |
||
136 | * @param string $qualifiedName |
||
137 | * @param null|string $alias |
||
138 | * @return $this |
||
139 | */ |
||
140 | 11 | public function addUseStatement($qualifiedName, $alias = null) { |
|
153 | |||
154 | /** |
||
155 | * Declares multiple use statements at once. |
||
156 | * |
||
157 | * @param ... use statements multiple qualified names |
||
158 | * @return $this |
||
159 | */ |
||
160 | 1 | public function declareUses() { |
|
166 | |||
167 | /** |
||
168 | * Declares a "use $fullClassName" with " as $alias" if $alias is available, |
||
169 | * and returns its alias (or not qualified classname) to be used in your actual |
||
170 | * php code. |
||
171 | * |
||
172 | * If the class has already been declared you get only the set alias. |
||
173 | * |
||
174 | * @param string $qualifiedName |
||
175 | * @param null|string $alias |
||
176 | * @return string the used alias |
||
177 | */ |
||
178 | 1 | public function declareUse($qualifiedName, $alias = null) { |
|
185 | |||
186 | /** |
||
187 | * Returns whether the given use statement is present |
||
188 | * |
||
189 | * @param string $qualifiedName |
||
190 | * @return boolean |
||
191 | */ |
||
192 | 3 | public function hasUseStatement($qualifiedName) { |
|
196 | |||
197 | /** |
||
198 | * Returns the usable alias for a qualified name |
||
199 | * |
||
200 | * @param string $qualifiedName |
||
201 | * @return string the alias |
||
202 | */ |
||
203 | 2 | public function getUseAlias($qualifiedName) { |
|
207 | |||
208 | /** |
||
209 | * Removes a use statement |
||
210 | * |
||
211 | * @param string $qualifiedName |
||
212 | * @return $this |
||
213 | */ |
||
214 | 3 | public function removeUseStatement($qualifiedName) { |
|
221 | |||
222 | /** |
||
223 | * Returns all use statements |
||
224 | * |
||
225 | * @return array collection of use statements |
||
226 | */ |
||
227 | 15 | public function getUseStatements() { |
|
230 | |||
231 | /** |
||
232 | * Sets a collection of methods |
||
233 | * |
||
234 | * @param PhpMethod[] $methods |
||
235 | * @return $this |
||
236 | */ |
||
237 | 1 | public function setMethods(array $methods) { |
|
249 | |||
250 | /** |
||
251 | * Adds a method |
||
252 | * |
||
253 | * @param PhpMethod $method |
||
254 | * @return $this |
||
255 | */ |
||
256 | 20 | public function setMethod(PhpMethod $method) { |
|
262 | |||
263 | /** |
||
264 | * Removes a method |
||
265 | * |
||
266 | * @param string|PhpMethod $nameOrMethod method name or Method instance |
||
267 | * @throws \InvalidArgumentException if the method cannot be found |
||
268 | * @return $this |
||
269 | */ |
||
270 | 2 | public function removeMethod($nameOrMethod) { |
|
284 | |||
285 | /** |
||
286 | * Checks whether a method exists or not |
||
287 | * |
||
288 | * @param string|PhpMethod $nameOrMethod method name or Method instance |
||
289 | * @return boolean `true` if it exists and `false` if not |
||
290 | */ |
||
291 | 2 | public function hasMethod($nameOrMethod) { |
|
298 | |||
299 | /** |
||
300 | * Returns a method |
||
301 | * |
||
302 | * @param string $nameOrMethod the methods name |
||
303 | * @throws \InvalidArgumentException if the method cannot be found |
||
304 | * @return PhpMethod |
||
305 | */ |
||
306 | 7 | public function getMethod($nameOrMethod) { |
|
317 | |||
318 | /** |
||
319 | * Returns all methods |
||
320 | * |
||
321 | * @return PhpMethod[] collection of methods |
||
322 | */ |
||
323 | 14 | public function getMethods() { |
|
326 | |||
327 | /** |
||
328 | * Returns all method names |
||
329 | * |
||
330 | * @return string[] |
||
331 | */ |
||
332 | 1 | public function getMethodNames() { |
|
335 | |||
336 | /** |
||
337 | * Clears all methods |
||
338 | * |
||
339 | * @return $this |
||
340 | */ |
||
341 | 1 | public function clearMethods() { |
|
349 | |||
350 | /** |
||
351 | * Generates a docblock from provided information |
||
352 | * |
||
353 | * @return $this |
||
354 | */ |
||
355 | 13 | public function generateDocblock() { |
|
366 | } |
||
367 |