1414
1515
1616/**
17- * Creates a representations based on reflection or source code.
17+ * Creates PhpGenerator representations from reflection objects or PHP source code.
1818 */
1919final class Factory
2020{
@@ -25,7 +25,11 @@ final class Factory
2525 private array $ extractorCache = [];
2626
2727
28- /** @param \ReflectionClass<object> $from */
28+ /**
29+ * Creates a ClassLike instance from a reflection object.
30+ * @param \ReflectionClass<object> $from
31+ * @param bool $withBodies load method bodies (requires nikic/php-parser, not available for anonymous/internal classes or interfaces)
32+ */
2933 public function fromClassReflection (
3034 \ReflectionClass $ from ,
3135 bool $ withBodies = false ,
@@ -206,6 +210,10 @@ public function fromMethodReflection(\ReflectionMethod $from): Method
206210 }
207211
208212
213+ /**
214+ * Creates a GlobalFunction or Closure instance from a reflection object.
215+ * @param bool $withBody load function body (requires nikic/php-parser, not available for closures or internal functions)
216+ */
209217 public function fromFunctionReflection (\ReflectionFunction $ from , bool $ withBody = false ): GlobalFunction |Closure
210218 {
211219 $ function = $ from ->isClosure () ? new Closure : new GlobalFunction ($ from ->name );
@@ -232,7 +240,10 @@ public function fromFunctionReflection(\ReflectionFunction $from, bool $withBody
232240 }
233241
234242
235- /** @param callable(): mixed $from */
243+ /**
244+ * Creates a Method, GlobalFunction, or Closure instance from a callable.
245+ * @param callable(): mixed $from
246+ */
236247 public function fromCallable (callable $ from ): Method |GlobalFunction |Closure
237248 {
238249 $ ref = Nette \Utils \Callback::toReflection ($ from );
@@ -367,13 +378,20 @@ public function fromObject(object $obj): Literal
367378 }
368379
369380
381+ /**
382+ * Parses PHP source code and returns the first class-like type found.
383+ * @throws Nette\InvalidStateException if the code contains no class
384+ */
370385 public function fromClassCode (string $ code ): ClassLike
371386 {
372387 $ classes = $ this ->fromCode ($ code )->getClasses ();
373388 return reset ($ classes ) ?: throw new Nette \InvalidStateException ('The code does not contain any class. ' );
374389 }
375390
376391
392+ /**
393+ * Parses PHP source code and returns the resulting PhpFile representation.
394+ */
377395 public function fromCode (string $ code ): PhpFile
378396 {
379397 $ reader = new Extractor ($ code );
0 commit comments