*/ class FacadePHPDocs{ /** * @var ReflectionClass */ private ReflectionClass $reflectionClass; /** * FacadePHPDocs constructor. * @throws ReflectionException */ public function __construct(string $classname) { $this->reflectionClass = new ReflectionClass($classname); } /** * @return ReflectionClass */ protected function getReflectionClass(): ReflectionClass { return $this->reflectionClass; } /** * @param ReflectionMethod $method * @return string|null */ protected function getReturnType(ReflectionMethod $method): ?string { $type = $method->getReturnType(); if(class_exists($type)){ return '\\' . $type . ' '; } elseif(is_null($type)){ return ''; } else{ return $type . ' '; } } /** * @param ReflectionParameter[] $parameters * @throws ReflectionException */ protected function processParameter(array $parameters): string { $output = []; $processValue = function (mixed $value) { return var_export($value, true); }; foreach ($parameters as $parameter){ if ($parameter->isOptional()){ if ($parameter->isDefaultValueConstant()){ $output[] = (string) $parameter->getType() . ' $' . $parameter->getName() . ' = ' . $parameter->getDefaultValueConstantName(); }else{ $output[] = (string) $parameter->getType() . ' $' . $parameter->getName() . ' = ' . $processValue($parameter->getDefaultValue()); } }else{ $output[] = (string) $parameter->getType() . ' $' . $parameter->getName(); } } return '(' . implode(', ', $output) . ')'; } /** * @throws ReflectionException */ function generate(){ $methods = $this->getReflectionClass()->getMethods(); foreach ($methods as $method){ echo $this->arrayToString([ ' * @method static', $this->getReturnType($method) . $method->getName() . $this->processParameter($method->getParameters()), PHP_EOL ]); } } /** * @throws ReflectionException */ static function make(string $classname): static { return new static($classname); } /** * @param array $array * @return string */ protected function arrayToString(array $array): string { return implode(' ', $array); } } try { FacadePHPDocs::make(FacadePHPDocs::class)->generate(); } catch (ReflectionException $e) { echo $e->getMessage() . PHP_EOL; } // example output // * @method static __construct(string $classname) // * @method static \ReflectionClass getReflectionClass() // * @method static ?string getReturnType(ReflectionMethod $method) // * @method static string processParameter(array $parameters) // * @method static generate() // * @method static static make(string $classname) // * @method static string arrayToString(array $array)