@@ -88,6 +88,7 @@ public function hasBracketedSyntax(): bool
88
88
89
89
90
90
/**
91
+ * Adds a use statement to the namespace for class, function or constant.
91
92
* @throws InvalidStateException
92
93
*/
93
94
public function addUse (string $ name , ?string $ alias = null , string $ of = self ::NameNormal): static
@@ -140,12 +141,18 @@ public function removeUse(string $name, string $of = self::NameNormal): void
140
141
}
141
142
142
143
144
+ /**
145
+ * Adds a use statement to the namespace for function.
146
+ */
143
147
public function addUseFunction (string $ name , ?string $ alias = null ): static
144
148
{
145
149
return $ this ->addUse ($ name , $ alias , self ::NameFunction);
146
150
}
147
151
148
152
153
+ /**
154
+ * Adds a use statement to the namespace for constant.
155
+ */
149
156
public function addUseConstant (string $ name , ?string $ alias = null ): static
150
157
{
151
158
return $ this ->addUse ($ name , $ alias , self ::NameConstant);
@@ -164,6 +171,9 @@ public function getUses(string $of = self::NameNormal): array
164
171
}
165
172
166
173
174
+ /**
175
+ * Resolves relative name to full name.
176
+ */
167
177
public function resolveName (string $ name , string $ of = self ::NameNormal): string
168
178
{
169
179
if (isset (Helpers::Keywords[strtolower ($ name )]) || $ name === '' ) {
@@ -185,12 +195,18 @@ public function resolveName(string $name, string $of = self::NameNormal): string
185
195
}
186
196
187
197
198
+ /**
199
+ * Simplifies type hint with relative names.
200
+ */
188
201
public function simplifyType (string $ type , string $ of = self ::NameNormal): string
189
202
{
190
203
return preg_replace_callback ('~[\w\x7f-\xff \\\\]+~ ' , fn ($ m ) => $ this ->simplifyName ($ m [0 ], $ of ), $ type );
191
204
}
192
205
193
206
207
+ /**
208
+ * Simplifies the full name of a class, function, or constant to a relative name.
209
+ */
194
210
public function simplifyName (string $ name , string $ of = self ::NameNormal): string
195
211
{
196
212
if (isset (Helpers::Keywords[strtolower ($ name )]) || $ name === '' ) {
@@ -235,6 +251,9 @@ public function simplifyName(string $name, string $of = self::NameNormal): strin
235
251
}
236
252
237
253
254
+ /**
255
+ * Adds a class-like type to the namespace. If it already exists, throws an exception.
256
+ */
238
257
public function add (ClassType |InterfaceType |TraitType |EnumType $ class ): static
239
258
{
240
259
$ name = $ class ->getName ();
@@ -254,41 +273,59 @@ public function add(ClassType|InterfaceType|TraitType|EnumType $class): static
254
273
}
255
274
256
275
276
+ /**
277
+ * Adds a class to the namespace. If it already exists, throws an exception.
278
+ */
257
279
public function addClass (string $ name ): ClassType
258
280
{
259
281
$ this ->add ($ class = new ClassType ($ name , $ this ));
260
282
return $ class ;
261
283
}
262
284
263
285
286
+ /**
287
+ * Adds an interface to the namespace. If it already exists, throws an exception.
288
+ */
264
289
public function addInterface (string $ name ): InterfaceType
265
290
{
266
291
$ this ->add ($ iface = new InterfaceType ($ name , $ this ));
267
292
return $ iface ;
268
293
}
269
294
270
295
296
+ /**
297
+ * Adds a trait to the namespace. If it already exists, throws an exception.
298
+ */
271
299
public function addTrait (string $ name ): TraitType
272
300
{
273
301
$ this ->add ($ trait = new TraitType ($ name , $ this ));
274
302
return $ trait ;
275
303
}
276
304
277
305
306
+ /**
307
+ * Adds an enum to the namespace. If it already exists, throws an exception.
308
+ */
278
309
public function addEnum (string $ name ): EnumType
279
310
{
280
311
$ this ->add ($ enum = new EnumType ($ name , $ this ));
281
312
return $ enum ;
282
313
}
283
314
284
315
316
+ /**
317
+ * Removes a class-like type from namespace.
318
+ */
285
319
public function removeClass (string $ name ): static
286
320
{
287
321
unset($ this ->classes [strtolower ($ name )]);
288
322
return $ this ;
289
323
}
290
324
291
325
326
+ /**
327
+ * Adds a function to the namespace. If it already exists, throws an exception.
328
+ */
292
329
public function addFunction (string $ name ): GlobalFunction
293
330
{
294
331
$ lower = strtolower ($ name );
@@ -302,14 +339,20 @@ public function addFunction(string $name): GlobalFunction
302
339
}
303
340
304
341
342
+ /**
343
+ * Removes a function type from namespace.
344
+ */
305
345
public function removeFunction (string $ name ): static
306
346
{
307
347
unset($ this ->functions [strtolower ($ name )]);
308
348
return $ this ;
309
349
}
310
350
311
351
312
- /** @return (ClassType|InterfaceType|TraitType|EnumType)[] */
352
+ /**
353
+ * Returns all class-like types in the namespace.
354
+ * @return (ClassType|InterfaceType|TraitType|EnumType)[]
355
+ */
313
356
public function getClasses (): array
314
357
{
315
358
$ res = [];
@@ -321,7 +364,10 @@ public function getClasses(): array
321
364
}
322
365
323
366
324
- /** @return GlobalFunction[] */
367
+ /**
368
+ * Returns all functions in the namespace.
369
+ * @return GlobalFunction[]
370
+ */
325
371
public function getFunctions (): array
326
372
{
327
373
$ res = [];
0 commit comments