@@ -313,6 +313,30 @@ public function addEnum(string $name): EnumType
313
313
}
314
314
315
315
316
+ /**
317
+ * Returns a class-like type from the namespace.
318
+ */
319
+ public function getClass (string $ name ): ClassType |InterfaceType |TraitType |EnumType
320
+ {
321
+ return $ this ->classes [strtolower ($ name )] ?? throw new Nette \InvalidArgumentException ("Class ' $ name' not found. " );
322
+ }
323
+
324
+
325
+ /**
326
+ * Returns all class-like types in the namespace.
327
+ * @return (ClassType|InterfaceType|TraitType|EnumType)[]
328
+ */
329
+ public function getClasses (): array
330
+ {
331
+ $ res = [];
332
+ foreach ($ this ->classes as $ class ) {
333
+ $ res [$ class ->getName ()] = $ class ;
334
+ }
335
+
336
+ return $ res ;
337
+ }
338
+
339
+
316
340
/**
317
341
* Removes a class-like type from namespace.
318
342
*/
@@ -340,42 +364,36 @@ public function addFunction(string $name): GlobalFunction
340
364
341
365
342
366
/**
343
- * Removes a function type from namespace.
367
+ * Returns a function from the namespace.
344
368
*/
345
- public function removeFunction (string $ name ): static
369
+ public function getFunction (string $ name ): GlobalFunction
346
370
{
347
- unset($ this ->functions [strtolower ($ name )]);
348
- return $ this ;
371
+ return $ this ->functions [strtolower ($ name )] ?? throw new Nette \InvalidArgumentException ("Function ' $ name' not found. " );
349
372
}
350
373
351
374
352
375
/**
353
- * Returns all class-like types in the namespace.
354
- * @return (ClassType|InterfaceType|TraitType|EnumType) []
376
+ * Returns all functions in the namespace.
377
+ * @return GlobalFunction []
355
378
*/
356
- public function getClasses (): array
379
+ public function getFunctions (): array
357
380
{
358
381
$ res = [];
359
- foreach ($ this ->classes as $ class ) {
360
- $ res [$ class ->getName ()] = $ class ;
382
+ foreach ($ this ->functions as $ fn ) {
383
+ $ res [$ fn ->getName ()] = $ fn ;
361
384
}
362
385
363
386
return $ res ;
364
387
}
365
388
366
389
367
390
/**
368
- * Returns all functions in the namespace.
369
- * @return GlobalFunction[]
391
+ * Removes a function type from namespace.
370
392
*/
371
- public function getFunctions ( ): array
393
+ public function removeFunction ( string $ name ): static
372
394
{
373
- $ res = [];
374
- foreach ($ this ->functions as $ fn ) {
375
- $ res [$ fn ->getName ()] = $ fn ;
376
- }
377
-
378
- return $ res ;
395
+ unset($ this ->functions [strtolower ($ name )]);
396
+ return $ this ;
379
397
}
380
398
381
399
0 commit comments