Core concepts

Debugging

When a type does not resolve the way you expect, there are two tools to find out why: debug mode and the autodoc:debug command.

Debug mode

By default, errors that occur during code analysis are silently ignored and the affected type resolves to unknown. Enable debug mode in your configuration file to surface them:

'debug' => [
    'enabled' => true,
    'ignore_dynamic_method_errors' => true,
    'ignore_unknown_method_errors_in_traits' => true,
],
  • ignore_dynamic_method_errors - skip errors about unknown methods on classes with a __call or __callStatic magic method.
  • ignore_unknown_method_errors_in_traits - skip errors about unknown methods in traits.

Inspecting resolved types

To see exactly what type autodoc resolves for a variable, add an @autodoc debug tag in a block comment inside the method you are interested in:

$subject = $this->subjects->find($id) ?? abort(404);

/** @autodoc debug $subject */

return $this->presenter->render($subject);

Then run the debug command.

For Laravel:

php artisan autodoc:debug

For other PHP projects:

vendor/bin/autodoc debug --config="/path/to/your/autodoc/config.php"

The command scans your code for @autodoc debug tags and prints the resolved type tree of each tagged variable, with the file and line it was found at. You can pass a directory or a single file as an argument to narrow the scan.

Other debug options:

  • /** @autodoc debug route */ prints the analyzed route object instead of a variable.
  • By default, autodoc fully resolves the type before printing it. Use --depth=N to unwrap only N levels and inspect the analyzer’s intermediate lazy types.

For more ways to improve type resolution, see tips to improve the generated documentation.

Previous
Docs viewer