Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Doctor Laravel Package

ahmed-bhs/doctrine-doctor

Doctrine Doctor is a runtime analysis tool for Doctrine ORM integrated into the Symfony Web Profiler. It detects real-world issues like N+1 queries, slow queries, missing indexes, hydration overhead, and injection risks, with actionable backtraces and suggestions.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Installation: Run composer require --dev ahmed-bhs/doctrine-doctor in your Symfony project.
  2. Enable Backtraces: Add profiling_collect_backtrace: true under doctrine.dbal in config/packages/dev/doctrine.yaml.
  3. First Use Case: Visit any page in your Symfony app in the dev environment, open the Symfony Web Profiler, and navigate to the Doctrine Doctor panel to inspect runtime Doctrine issues.

Implementation Patterns

Daily Workflow

  1. Development Phase:

    • Write code as usual, then check the Doctrine Doctor panel after each significant change.
    • Focus on Critical and Warning issues first, then address Info issues progressively.
  2. Code Review:

    • Use Doctrine Doctor to catch runtime issues early.
    • Share configuration settings and common patterns with your team to maintain consistency.
  3. Testing:

    • Run tests to ensure fixes don’t break functionality.
    • Review the staging environment with production-like data before deployment.

Integration Tips

  • Symfony Events: Leverage Symfony events to integrate Doctrine Doctor with custom workflows (e.g., pre-commit hooks).
  • CI/CD: Add a step to run Doctrine Doctor in your CI pipeline to catch issues early.
  • Custom Analyzers: Extend the package by creating custom analyzers for project-specific requirements.

Example Workflow for N+1 Queries

  1. Detect: Doctrine Doctor flags an N+1 query pattern in your Twig template.
  2. Locate: Use the backtrace to identify the exact line in your template or controller.
  3. Fix: Implement eager loading with addSelect() in your QueryBuilder.
  4. Verify: Refresh the page and confirm the issue is resolved in the Doctrine Doctor panel.

Gotchas and Tips

Common Pitfalls

  • Backtrace Disabled: If backtraces aren’t showing, ensure profiling_collect_backtrace: true is set in your Doctrine configuration.
  • High Thresholds: Some analyzers (e.g., slow_query) have default thresholds that might be too high for your environment. Adjust them in config/packages/dev/doctrine_doctor.yaml.
  • Production Environment: Doctrine Doctor is designed for development only. Ensure it’s disabled in production by setting enabled: false in the config.

Debugging Tips

  • No Issues Detected: Verify that your page executes database queries and that doctrine_doctor.enabled is set to true.
  • Permission Issues: For the Missing Index Analyzer, ensure your database user has SELECT permissions to execute EXPLAIN queries.
  • Performance Overhead: Doctrine Doctor adds minimal overhead during development. If performance is critical, disable it temporarily with enabled: false.

Configuration Quirks

  • Analyzer-Specific Settings: Some analyzers (e.g., n_plus_one) allow custom thresholds. Adjust these based on your project’s needs.
  • Environment-Specific Config: Use environment variables or separate config files for different environments (e.g., dev, staging).

Extension Points

  • Custom Analyzers: Extend the package by creating custom analyzers for project-specific Doctrine issues.
  • Symfony Events: Listen to Doctrine Doctor events (e.g., doctrine_doctor.issue.detected) to integrate with custom logic or logging.
  • Profiler Integration: Customize the Profiler panel by overriding templates or adding your own data collectors.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
phalcon/cli-options-parser
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata