1 | <?php |
||
34 | abstract class AbstractPhpStruct extends AbstractModel implements NamespaceInterface, DocblockInterface { |
||
35 | |||
36 | use DocblockPart; |
||
37 | use LongDescriptionPart; |
||
38 | use QualifiedNamePart; |
||
39 | |||
40 | /** @var Map */ |
||
41 | private $useStatements; |
||
42 | |||
43 | /** @var Set */ |
||
44 | private $requiredFiles; |
||
45 | |||
46 | /** @var Map */ |
||
47 | private $methods; |
||
48 | |||
49 | /** |
||
50 | * Creates a new struct |
||
51 | * |
||
52 | * @param string $name the fqcn |
||
53 | * @return static |
||
54 | */ |
||
55 | 13 | public static function create(?string $name = null) { |
|
58 | |||
59 | /** |
||
60 | * Creates a new struct |
||
61 | * |
||
62 | * @param string $name the fqcn |
||
63 | */ |
||
64 | 56 | public function __construct(?string $name = null) { |
|
71 | |||
72 | /** |
||
73 | * Sets requried files |
||
74 | * |
||
75 | * @param array $files |
||
76 | * @return $this |
||
77 | */ |
||
78 | 1 | public function setRequiredFiles(array $files) { |
|
83 | |||
84 | /** |
||
85 | * Adds a new required file |
||
86 | * |
||
87 | * @param string $file |
||
88 | * @return $this |
||
89 | */ |
||
90 | 2 | public function addRequiredFile(string $file) { |
|
95 | |||
96 | /** |
||
97 | * Returns required files |
||
98 | * |
||
99 | * @return Set collection of filenames |
||
100 | */ |
||
101 | 17 | public function getRequiredFiles(): Set { |
|
104 | |||
105 | /** |
||
106 | * Sets use statements |
||
107 | * |
||
108 | * @see #addUseStatement |
||
109 | * @see #declareUses() |
||
110 | * @param array $useStatements |
||
111 | * @return $this |
||
112 | */ |
||
113 | 1 | public function setUseStatements(array $useStatements) { |
|
121 | |||
122 | /** |
||
123 | * Adds a use statement with an optional alias |
||
124 | * |
||
125 | * @param string $qualifiedName |
||
126 | * @param null|string $alias |
||
127 | * @return $this |
||
128 | */ |
||
129 | 5 | public function addUseStatement(string $qualifiedName, string $alias = null) { |
|
142 | |||
143 | /** |
||
144 | * Clears all use statements |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | 1 | public function clearUseStatements() { |
|
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(string ...$uses) { |
|
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(string $qualifiedName, string $alias = null) { |
|
185 | |||
186 | /** |
||
187 | * Returns whether the given use statement is present |
||
188 | * |
||
189 | * @param string $qualifiedName |
||
190 | * @return bool |
||
191 | */ |
||
192 | 3 | public function hasUseStatement(string $qualifiedName): bool { |
|
195 | |||
196 | /** |
||
197 | * Returns the usable alias for a qualified name |
||
198 | * |
||
199 | * @param string $qualifiedName |
||
200 | * @return string the alias |
||
201 | */ |
||
202 | 1 | public function getUseAlias(string $qualifiedName): string { |
|
205 | |||
206 | /** |
||
207 | * Removes a use statement |
||
208 | * |
||
209 | * @param string $qualifiedName |
||
210 | * @return $this |
||
211 | */ |
||
212 | 3 | public function removeUseStatement(string $qualifiedName) { |
|
216 | |||
217 | /** |
||
218 | * Returns all use statements |
||
219 | * |
||
220 | * @return Map collection of use statements |
||
221 | */ |
||
222 | 17 | public function getUseStatements(): Map { |
|
225 | |||
226 | /** |
||
227 | * Sets a collection of methods |
||
228 | * |
||
229 | * @param PhpMethod[] $methods |
||
230 | * @return $this |
||
231 | */ |
||
232 | 1 | public function setMethods(array $methods) { |
|
244 | |||
245 | /** |
||
246 | * Adds a method |
||
247 | * |
||
248 | * @param PhpMethod $method |
||
249 | * @return $this |
||
250 | */ |
||
251 | 15 | public function setMethod(PhpMethod $method) { |
|
257 | |||
258 | /** |
||
259 | * Removes a method |
||
260 | * |
||
261 | * @param string|PhpMethod $nameOrMethod method name or Method instance |
||
262 | * @throws \InvalidArgumentException if the method cannot be found |
||
263 | * @return $this |
||
264 | */ |
||
265 | 2 | public function removeMethod($nameOrMethod) { |
|
279 | |||
280 | /** |
||
281 | * Checks whether a method exists or not |
||
282 | * |
||
283 | * @param string|PhpMethod $nameOrMethod method name or Method instance |
||
284 | * @return bool `true` if it exists and `false` if not |
||
285 | */ |
||
286 | 2 | public function hasMethod($nameOrMethod): bool { |
|
293 | |||
294 | /** |
||
295 | * Returns a method |
||
296 | * |
||
297 | * @param string $nameOrMethod the methods name |
||
298 | * @throws \InvalidArgumentException if the method cannot be found |
||
299 | * @return PhpMethod |
||
300 | */ |
||
301 | 9 | public function getMethod($nameOrMethod): PhpMethod { |
|
312 | |||
313 | /** |
||
314 | * Returns all methods |
||
315 | * |
||
316 | * @return Map collection of methods |
||
317 | */ |
||
318 | 17 | public function getMethods(): Map { |
|
321 | |||
322 | /** |
||
323 | * Returns all method names |
||
324 | * |
||
325 | * @return Set |
||
326 | */ |
||
327 | 1 | public function getMethodNames(): Set { |
|
330 | |||
331 | /** |
||
332 | * Clears all methods |
||
333 | * |
||
334 | * @return $this |
||
335 | */ |
||
336 | 1 | public function clearMethods() { |
|
344 | |||
345 | /** |
||
346 | * Generates a docblock from provided information |
||
347 | * |
||
348 | * @return $this |
||
349 | */ |
||
350 | 11 | public function generateDocblock() { |
|
361 | } |
||
362 |