PHPackages                             ahmed-bhs/doctrine-doctor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ahmed-bhs/doctrine-doctor

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

ahmed-bhs/doctrine-doctor
=========================

Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.

v2.7.3(2mo ago)813.1k↑13.3%7[18 issues](https://github.com/ahmed-bhs/doctrine-doctor/issues)MITPHPPHP ^8.4CI failing

Since Nov 10Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/ahmed-bhs/doctrine-doctor)[ Packagist](https://packagist.org/packages/ahmed-bhs/doctrine-doctor)[ Docs](https://github.com/ahmed-bhs/doctrine-doctor)[ RSS](/packages/ahmed-bhs-doctrine-doctor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (44)Versions (68)Used By (0)

Doctrine Doctor
===============

[](#doctrine-doctor)

[![Doctrine Doctor Logo](docs/images/logo.png)](docs/images/logo.png)

**Runtime Analysis Tool for Doctrine ORM — Integrated into Symfony Web Profiler**

[![PHP 8.4+](https://camo.githubusercontent.com/c90b4efafbe12e9170f3386518809781acbbe82e70a6c34e5065f6ce7b042dbb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342b2d3737374242342e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://php.net)[![Symfony 6.x | 7.x | 8.x](https://camo.githubusercontent.com/bd39abbe34f5fba93b479ddffa75b57f980a3fdeece59a4e6b7d2fa226690985/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d362e78253230253743253230372e78253230253743253230382e782d3030303030302e7376673f6c6f676f3d73796d666f6e79266c6f676f436f6c6f723d7768697465)](https://symfony.com)[![Doctrine ORM](https://camo.githubusercontent.com/415ff0ba1fcee9f3fd01995b14daf9745e4be0a9fe930712e784d6c061d39716/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f637472696e652d332e78253230253743253230342e782d4643364133312e7376673f6c6f676f3d646f637472696e65266c6f676f436f6c6f723d7768697465)](https://www.doctrine-project.org)[![License MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![CI](https://github.com/ahmed-bhs/doctrine-doctor/workflows/CI/badge.svg)](https://github.com/ahmed-bhs/doctrine-doctor/actions)[![PHPStan Level 8](https://camo.githubusercontent.com/c51bda247654363d3e30bc352674dd761a9557803a14af0226eb411d6dc0006b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d627269676874677265656e2e737667)](https://phpstan.org)[![Code Style](https://camo.githubusercontent.com/34b10db0caa29bacd49bda5c437a8de95385f036f3230b31fa605326e18da22c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f64652532305374796c652d5053522d2d31322d626c75652e737667)](https://www.php-fig.org/psr/psr-12/)[![Packagist Version](https://camo.githubusercontent.com/bb8c1246d5932a83eb24151a7d9d328c740dff58321d555ddc0c8209cb7ef961/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61686d65642d6268732f646f637472696e652d646f63746f722e737667)](https://packagist.org/packages/ahmed-bhs/doctrine-doctor)

**Why Runtime Analysis?**

Unlike static analysis tools (PHPStan, Psalm) that analyze code without execution, Doctrine Doctor:

- **Detects runtime doctrine issues** by analyzing real execution context (actual parameters, data volume, query plans), including N+1 queries, real query performance bottlenecks, and missing indexes.
- **Integrated into your workflow**: Results appear directly in Symfony Web Profiler during development
    - 📍 Backtrace: Points to exact template line
    - 💡 Suggestion: Use `->addSelect(..)` to eager load products

 [![Doctrine Doctor Demo](https://github.com/ahmed-bhs/doctrine-doctor-assets/raw/main/demo-styled.png)](https://github.com/ahmed-bhs/doctrine-doctor-assets/raw/main/demo-styled.png)

---

Features
--------

[](#features)

### 66 Specialized Analyzers

[](#66-specialized-analyzers)

- **Performance** — Detects N+1 queries, missing database indexes, slow queries, excessive hydration, findAll() without limits, setMaxResults() with collection joins, too many JOINs, and query caching opportunities
- **Security** — Identifies DQL/SQL injection vulnerabilities, QueryBuilder SQL injection risks, sensitive data exposure in serialization, unprotected sensitive fields, and insecure random generators
- **Integrity** — Detects cascade configuration issues, bidirectional inconsistencies, missing orphan removal, type mismatches, float usage for money, uninitialized collections, EntityManager in entities, and architectural violations
- **Configuration** — Validates database charset/collation settings, timezone handling, Gedmo trait configurations, MySQL strict mode, and other database-level configurations

---

⚡ Quick Start (30 seconds)
--------------------------

[](#-quick-start-30-seconds)

**Step 1: Install**

```
composer require --dev ahmed-bhs/doctrine-doctor
```

**Step 2: That's it!**

Auto-configured via [Symfony Flex](https://github.com/symfony/recipes-contrib/pull/1882). No YAML, no configuration files needed.

**Step 3: See it in action**

1. Refresh any page in your Symfony app (in `dev` environment)
2. Open the **Symfony Web Profiler** (bottom toolbar)
3. Click the **"Doctrine Doctor"** panel 🩺

Configuration (Optional)
------------------------

[](#configuration-optional)

Configure thresholds in `config/packages/dev/doctrine_doctor.yaml`:

```
doctrine_doctor:
    analyzers:
        n_plus_one:
            threshold: 5  # default, lower to 3 to be stricter
        slow_query:
            threshold: 100  # milliseconds (default)
```

**Enable backtraces** to see WHERE in your code issues originate:

```
# config/packages/dev/doctrine.yaml
doctrine:
    dbal:
        profiling_collect_backtrace: true
```

[Full configuration reference →](docs/user-guide/configuration.md)

---

Example: N+1 Query Detection
----------------------------

[](#example-n1-query-detection)

**Before — 100 queries****After — 1 query**```
$users = $repository->findAll();
```

```
{% for user in users %}
    {{ user.profile.bio }}
{% endfor %}
```

```
$users = $repository
    ->createQueryBuilder('u')
    ->leftJoin('u.profile', 'p')
    ->addSelect('p')
    ->getQuery()
    ->getResult();
```

**Doctrine Doctor detects the N+1 pattern at runtime** — reports query count, execution time, points to the exact template line, and suggests eager loading with `addSelect()`.

---

Documentation
-------------

[](#documentation)

DocumentDescription[**Full Analyzers List**](docs/user-guide/analyzers.md)Complete catalog of all **66 analyzers** covering performance, security, integrity, and configuration - find the perfect analyzer for your specific needs[**Architecture Guide**](docs/advanced/architecture.md)Deep dive into **system design**, architecture patterns, and technical internals - understand how Doctrine Doctor works under the hood[**Configuration Reference**](docs/user-guide/configuration.md)Comprehensive guide to **all configuration options** - customize analyzers, thresholds, and outputs to match your workflow[**Template Security**](docs/advanced/template-security.md)Essential **security best practices** for PHP templates - prevent XSS attacks and ensure safe template rendering---

Contributing
------------

[](#contributing)

See [Contributing Guide](docs/contributing/overview.md) for guidelines.

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) for details.

---

**Created by [Ahmed EBEN HASSINE](https://github.com/ahmed-bhs)**

[ ![Sponsor me on GitHub](https://camo.githubusercontent.com/f698109ec01af65a28390aa047f262c778df53dfcf048e7e573017e4e3fe0a4c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d53706f6e736f72266d6573736167653d476974487562266c6f676f3d676974687562267374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://github.com/sponsors/ahmed-bhs)[ ![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/w6ZhBSGX2)

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance83

Actively maintained with recent releases

Popularity39

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

46

Last Release

55d ago

Major Versions

v1.0.2 → v2.0.0-beta.12026-02-11

v1.0.3 → v2.0.02026-02-20

v1.0.4 → v2.1.2-beta.12026-03-03

v1.0.5 → v2.2.12026-03-04

1.x-dev → v2.5.02026-03-10

PHP version history (3 changes)v0.1.0-alpha.2PHP ^8.1

v1.0.0PHP ^8.2

v2.0.0-beta.1PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3297c1384e75483020a47fb9a7614a02bf02ba06f286bc56bf1bb81a25941660?d=identicon)[ahmed-bhs](/maintainers/ahmed-bhs)

---

Top Contributors

[![ahmed-bhs](https://avatars.githubusercontent.com/u/19672303?v=4)](https://github.com/ahmed-bhs "ahmed-bhs (285 commits)")[![ahmedebn](https://avatars.githubusercontent.com/u/53824858?v=4)](https://github.com/ahmedebn "ahmedebn (16 commits)")[![ClementDuverge](https://avatars.githubusercontent.com/u/6507745?v=4)](https://github.com/ClementDuverge "ClementDuverge (1 commits)")

---

Tags

database-optimizationdebugging-toolsdeveloper-toolsdoctrine-analyzerdoctrine-ormn-plus-one-detectionorm-performanceperformance-analysisquery-optimizationruntime-analysissql-profilersymfony-bundlesymfony-profilersymfonyprofilersecurityperformancedebuggingdoctrinedqlcode qualitySymfony Bundledoctrine-ormn-plus-oneBest-Practicesdeveloper-toolsanalyzerquery-optimizationdevelopment-toolsweb-profilerperformance-monitoringruntime-analysisquery-analysisdatabase-performancequery-analyzern-plus-one-detectiondoctrine-analyzersql-profilerorm-debuggingmissing-indexesslow-queries

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ahmed-bhs-doctrine-doctor/health.svg)

```
[![Health](https://phpackages.com/badges/ahmed-bhs-doctrine-doctor/health.svg)](https://phpackages.com/packages/ahmed-bhs-doctrine-doctor)
```

###  Alternatives

[debesha/doctrine-hydration-profiler-bundle

Information about hydration of doctrine entities at the profiler

133593.2k1](/packages/debesha-doctrine-hydration-profiler-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[andanteproject/soft-deletable-bundle

A Symfony Bundle to handle soft deletable with Doctrine Entities

1028.3k](/packages/andanteproject-soft-deletable-bundle)[heymoon/doctrine-psql-enum

Store PHP native enums as PostgeSQL custom enum types

254.9k](/packages/heymoon-doctrine-psql-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
