- How do I install spatie/php-type-graph in a Laravel project?
- Run `composer require spatie/php-type-graph` in your project root. The package requires PHP 8.1+ and works with any PHP project, including Laravel. No Laravel-specific setup is needed beyond installation.
- Can this package help visualize Laravel-specific dependencies like facades or service container bindings?
- No, this package focuses on raw PHP type relationships (classes, interfaces, etc.) and doesn’t resolve Laravel-specific constructs like facades or service container bindings. For those, consider alternatives like Symfony’s dependency injection tools.
- Is spatie/php-type-graph stable enough for production use?
- The package is archived and labeled as a work in progress, meaning its API may change unpredictably. Use it cautiously—best suited for experimental analysis or development-time tooling rather than production-critical workflows.
- How do I generate a type graph and visualize it?
- The package outputs a graph structure (likely JSON or DOT format). You’ll need to post-process it using tools like Graphviz, Mermaid.js, or custom scripts. Example: `php vendor/bin/type-graph generate --format=json > graph.json` followed by visualization.
- What Laravel versions does this package support?
- The package works with any Laravel version but requires PHP 8.1+. Since it’s PHP-agnostic, it doesn’t depend on Laravel’s internals, so compatibility is determined by your PHP version and Laravel’s PHP support policy.
- Can I integrate this into CI/CD for automated type analysis?
- Yes, you can run the package during CI (e.g., via a Composer script or GitHub Action) to generate graphs for review. Add it to `composer.json` scripts like `post-autoload-dump` or create a custom Artisan command to trigger analysis on demand.
- What are the alternatives to spatie/php-type-graph for type analysis?
- For dependency graphs, consider Symfony’s dependency injection tools or custom traversal scripts. For static type analysis, use phpstan (with `--generate-report`) or Psalm, which offer more stability and Laravel integration. For visualization, Graphviz or Mermaid.js can work with any graph data.
- How does this package handle circular dependencies or unused types?
- The package scans type relationships but doesn’t natively detect circular dependencies or unused types. You’d need to post-process the generated graph (e.g., with custom scripts or tools like phpstan) to identify these issues.
- Can I use this to generate documentation for my Laravel project?
- Yes, the type graph can serve as a foundation for documentation. Export the graph to JSON or DOT, then visualize it in tools like Mermaid.js or Graphviz. This is useful for onboarding or architectural overviews, though manual curation may be needed.
- What happens if the package’s API changes or breaks?
- Since the package is archived, forks or updates may be needed to maintain compatibility. Treat it as experimental—either monitor for changes or fork it to stabilize the API for your project’s needs.