@@ -88,6 +88,7 @@ public function hasBracketedSyntax(): bool
8888
8989
9090 /**
91+ * Adds a use statement to the namespace for class, function or constant.
9192 * @throws InvalidStateException
9293 */
9394 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
140141 }
141142
142143
144+ /**
145+ * Adds a use statement to the namespace for function.
146+ */
143147 public function addUseFunction (string $ name , ?string $ alias = null ): static
144148 {
145149 return $ this ->addUse ($ name , $ alias , self ::NameFunction);
146150 }
147151
148152
153+ /**
154+ * Adds a use statement to the namespace for constant.
155+ */
149156 public function addUseConstant (string $ name , ?string $ alias = null ): static
150157 {
151158 return $ this ->addUse ($ name , $ alias , self ::NameConstant);
@@ -164,6 +171,9 @@ public function getUses(string $of = self::NameNormal): array
164171 }
165172
166173
174+ /**
175+ * Resolves relative name to full name.
176+ */
167177 public function resolveName (string $ name , string $ of = self ::NameNormal): string
168178 {
169179 if (isset (Helpers::Keywords[strtolower ($ name )]) || $ name === '' ) {
@@ -185,12 +195,18 @@ public function resolveName(string $name, string $of = self::NameNormal): string
185195 }
186196
187197
198+ /**
199+ * Simplifies type hint with relative names.
200+ */
188201 public function simplifyType (string $ type , string $ of = self ::NameNormal): string
189202 {
190203 return preg_replace_callback ('~[\w\x7f-\xff \\\\]+~ ' , fn ($ m ) => $ this ->simplifyName ($ m [0 ], $ of ), $ type );
191204 }
192205
193206
207+ /**
208+ * Simplifies the full name of a class, function, or constant to a relative name.
209+ */
194210 public function simplifyName (string $ name , string $ of = self ::NameNormal): string
195211 {
196212 if (isset (Helpers::Keywords[strtolower ($ name )]) || $ name === '' ) {
@@ -235,6 +251,9 @@ public function simplifyName(string $name, string $of = self::NameNormal): strin
235251 }
236252
237253
254+ /**
255+ * Adds a class-like type to the namespace. If it already exists, throws an exception.
256+ */
238257 public function add (ClassType |InterfaceType |TraitType |EnumType $ class ): static
239258 {
240259 $ name = $ class ->getName ();
@@ -254,41 +273,59 @@ public function add(ClassType|InterfaceType|TraitType|EnumType $class): static
254273 }
255274
256275
276+ /**
277+ * Adds a class to the namespace. If it already exists, throws an exception.
278+ */
257279 public function addClass (string $ name ): ClassType
258280 {
259281 $ this ->add ($ class = new ClassType ($ name , $ this ));
260282 return $ class ;
261283 }
262284
263285
286+ /**
287+ * Adds an interface to the namespace. If it already exists, throws an exception.
288+ */
264289 public function addInterface (string $ name ): InterfaceType
265290 {
266291 $ this ->add ($ iface = new InterfaceType ($ name , $ this ));
267292 return $ iface ;
268293 }
269294
270295
296+ /**
297+ * Adds a trait to the namespace. If it already exists, throws an exception.
298+ */
271299 public function addTrait (string $ name ): TraitType
272300 {
273301 $ this ->add ($ trait = new TraitType ($ name , $ this ));
274302 return $ trait ;
275303 }
276304
277305
306+ /**
307+ * Adds an enum to the namespace. If it already exists, throws an exception.
308+ */
278309 public function addEnum (string $ name ): EnumType
279310 {
280311 $ this ->add ($ enum = new EnumType ($ name , $ this ));
281312 return $ enum ;
282313 }
283314
284315
316+ /**
317+ * Removes a class-like type from namespace.
318+ */
285319 public function removeClass (string $ name ): static
286320 {
287321 unset($ this ->classes [strtolower ($ name )]);
288322 return $ this ;
289323 }
290324
291325
326+ /**
327+ * Adds a function to the namespace. If it already exists, throws an exception.
328+ */
292329 public function addFunction (string $ name ): GlobalFunction
293330 {
294331 $ lower = strtolower ($ name );
@@ -302,14 +339,20 @@ public function addFunction(string $name): GlobalFunction
302339 }
303340
304341
342+ /**
343+ * Removes a function type from namespace.
344+ */
305345 public function removeFunction (string $ name ): static
306346 {
307347 unset($ this ->functions [strtolower ($ name )]);
308348 return $ this ;
309349 }
310350
311351
312- /** @return (ClassType|InterfaceType|TraitType|EnumType)[] */
352+ /**
353+ * Returns all class-like types in the namespace.
354+ * @return (ClassType|InterfaceType|TraitType|EnumType)[]
355+ */
313356 public function getClasses (): array
314357 {
315358 $ res = [];
@@ -321,7 +364,10 @@ public function getClasses(): array
321364 }
322365
323366
324- /** @return GlobalFunction[] */
367+ /**
368+ * Returns all functions in the namespace.
369+ * @return GlobalFunction[]
370+ */
325371 public function getFunctions (): array
326372 {
327373 $ res = [];
0 commit comments