@@ -313,6 +313,30 @@ public function addEnum(string $name): EnumType
313313 }
314314
315315
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+
316340 /**
317341 * Removes a class-like type from namespace.
318342 */
@@ -340,42 +364,36 @@ public function addFunction(string $name): GlobalFunction
340364
341365
342366 /**
343- * Removes a function type from namespace.
367+ * Returns a function from the namespace.
344368 */
345- public function removeFunction (string $ name ): static
369+ public function getFunction (string $ name ): GlobalFunction
346370 {
347- unset($ this ->functions [strtolower ($ name )]);
348- return $ this ;
371+ return $ this ->functions [strtolower ($ name )] ?? throw new Nette \InvalidArgumentException ("Function ' $ name' not found. " );
349372 }
350373
351374
352375 /**
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 []
355378 */
356- public function getClasses (): array
379+ public function getFunctions (): array
357380 {
358381 $ res = [];
359- foreach ($ this ->classes as $ class ) {
360- $ res [$ class ->getName ()] = $ class ;
382+ foreach ($ this ->functions as $ fn ) {
383+ $ res [$ fn ->getName ()] = $ fn ;
361384 }
362385
363386 return $ res ;
364387 }
365388
366389
367390 /**
368- * Returns all functions in the namespace.
369- * @return GlobalFunction[]
391+ * Removes a function type from namespace.
370392 */
371- public function getFunctions ( ): array
393+ public function removeFunction ( string $ name ): static
372394 {
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 ;
379397 }
380398
381399
0 commit comments