PHPackages                             degraciamathieu/php-dep - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. degraciamathieu/php-dep

ActiveProject[Utility &amp; Helpers](/categories/utility)

degraciamathieu/php-dep
=======================

PHP dependency analyzer - extract and visualize class relationships

v1.0.0(3mo ago)412↓70%MITPHPPHP &gt;=8.2CI passing

Since Mar 26Pushed 3mo agoCompare

[ Source](https://github.com/DeGraciaMathieu/php-dep)[ Packagist](https://packagist.org/packages/degraciamathieu/php-dep)[ RSS](/packages/degraciamathieu-php-dep/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

php-dep
=======

[](#php-dep)

PHP command-line dependency analyzer. Extracts and visualizes all class relationships in a project: inheritance, interfaces, traits, injections, instantiations, static calls, docblocks.

Installation
------------

[](#installation)

```
git clone
cd php-dep
composer install
chmod +x bin/php-dep
```

For global access:

```
ln -s /absolute/path/to/bin/php-dep /usr/local/bin/php-dep
```

Quick start
-----------

[](#quick-start)

```
# Analyze the current directory
./bin/php-dep analyze

# Analyze a specific project
./bin/php-dep analyze /path/to/project/src

# JSON output (for scripts, CI, jq…)
./bin/php-dep analyze src/ --format=json -q

# Zoom in on a class
./bin/php-dep analyze src/ --class='App\Service\UserService'
```

`analyze` command
-----------------

[](#analyze-command)

```
php-dep analyze [] [options]

```

`` is optional, defaults to `.`

### Options

[](#options)

OptionShortcutDescription`--format=text|json``-f`Output format (default: `text`)`--class=FQCN``-c`Focus on a class (full FQCN)`--sort=alpha|deps|fanin``-s`Table sort: alphabetical, number of outgoing dependencies, number of incoming dependencies (default: `alpha`)`--limit=N``-l`Limit output to N classes`--exclude=dir`Exclude a directory (can be used multiple times)`--include-vendor`Include the `vendor/` directory in the analysis`--skip-docblocks`Ignore `@param`/`@return`/`@throws` annotations`--quiet``-q`Suppresses the progress bar and warnings (stdout preserved)`--verbose``-v`Show warning details### Exit codes

[](#exit-codes)

CodeMeaning`0`Success`1`Parsing error(s)`2`Internal error`3`Invalid arguments---

Examples
--------

[](#examples)

### Project overview

[](#project-overview)

```
./bin/php-dep analyze src/
```

Displays a table with, for each class: type, number of outgoing dependencies (what it uses), incoming dependencies (what uses it), and source file.

### Find the most coupled classes

[](#find-the-most-coupled-classes)

```
# Highest dependency consumers
./bin/php-dep analyze src/ --sort=deps --limit=10

# Most used by others (high fan-in)
./bin/php-dep analyze src/ --sort=fanin --limit=10
```

### Inspect a class

[](#inspect-a-class)

```
./bin/php-dep analyze src/ --class='PhpDep\Parser\PhpFileParser' -v
```

Displays two tables: what the class uses (outgoing dependencies) and who uses it (incoming dependencies), with the relationship type and source line.

### JSON pipeline with `jq`

[](#json-pipeline-with-jq)

```
# Count classes
./bin/php-dep analyze src/ -f json -q | jq '.meta.class_count'

# List all inheritance relationships
./bin/php-dep analyze src/ -f json -q | jq '[.edges[] | select(.type == "extends")]'

# Find classes with no dependants (leaves)
./bin/php-dep analyze src/ -f json -q | jq '[.classes[] | select(.dependants | length == 0) | .fqcn]'

# Find dependencies of a specific class
./bin/php-dep analyze src/ -f json -q | jq '.classes[] | select(.fqcn == "App\\Service\\UserService") | .dependencies'
```

### Exclude directories

[](#exclude-directories)

```
./bin/php-dep analyze . --exclude=tests --exclude=fixtures --exclude=migrations
```

### Analysis without vendor

[](#analysis-without-vendor)

By default, `vendor/` is excluded from the analysis but third-party classes appear as `external` nodes in the graph. No additional option is needed to ignore them entirely.

To analyze the vendor itself:

```
./bin/php-dep analyze . --include-vendor
```

---

JSON output structure
---------------------

[](#json-output-structure)

```
{
  "meta": {
    "version": "1.0",
    "generated_at": "2026-02-26T10:00:00+00:00",
    "analyzed_path": "/path/to/project",
    "file_count": 42,
    "class_count": 38,      // internal nodes only
    "node_count": 95,       // internal + external (vendor, built-in)
    "edge_count": 312,
    "warning_count": 2
  },
  "classes": [
    {
      "fqcn": "App\\Service\\UserService",
      "type": "class",      // class | interface | trait | enum
      "file": "/path/to/UserService.php",
      "line": 12,
      "dependencies": ["App\\Repository\\UserRepository", "Psr\\Log\\LoggerInterface"],
      "dependants":   ["App\\Controller\\UserController"]
    }
  ],
  "edges": [
    {
      "source":     "App\\Service\\UserService",
      "target":     "App\\Repository\\UserRepository",
      "type":       "param_type",   // see relationship types below
      "confidence": "certain",      // certain | high | medium | low
      "file":       "/path/to/UserService.php",
      "line":       23,
      "metadata":   {}
    }
  ],
  "warnings": [
    {
      "type":    "dynamic_instantiation",
      "file":    "/path/to/Factory.php",
      "line":    45,
      "message": "Dynamic instantiation: new $variable()"
    }
  ]
}
```

---

Relationship types (`edge.type`)
--------------------------------

[](#relationship-types-edgetype)

### Tier 1 — Maximum certainty (AST)

[](#tier-1--maximum-certainty-ast)

TypeDescription`extends`Class or interface inheritance`implements`Interface implementation`uses_trait`Trait usage`param_type`Type hint on a method parameter`return_type`Method return type`property_type`Class property type`instantiates``new Foo()``static_call``Foo::method()``static_property``Foo::$prop``const_access``Foo::CONST``instanceof``$x instanceof Foo``catches``catch (FooException $e)`### Tier 2 — High confidence (docblocks)

[](#tier-2--high-confidence-docblocks)

Extracted from `@param`, `@return`, `@var`, `@throws`. Confidence: `high`.

TypeSource`docblock_param``@param FooType $x``docblock_return``@return FooType``docblock_var``@var FooType``docblock_throws``@throws FooException`### Confidence levels

[](#confidence-levels)

ValueMeaning`certain`Structural relationship guaranteed by the AST`high`Docblock, highly probable`medium`Ambiguous pattern (`instanceof`)`low`Dynamic pattern---

Warnings
--------

[](#warnings)

TypeTrigger`dynamic_instantiation``new $variable()` — class unknown at static analysis time`dynamic_call`Unresolvable dynamic call`parse_error`Invalid or unreadable PHP fileWarnings are printed to `stderr`. The JSON output includes them in `warnings[]`. With `-v`, the text output lists them at the end of the report.

---

How it works
------------

[](#how-it-works)

- **Discovery**: `git ls-files` if inside a git repository, otherwise `RecursiveDirectoryIterator`. The `vendor/`, `node_modules/`, and `.git/` directories are excluded by default.
- **Parsing**: [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser) v5. The `NameResolver` runs first in the traverser: all downstream names are resolved FQCNs.
- **Docblocks**: [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) for `@param`, `@return`, `@var`, `@throws`.
- **Memory**: each file's AST is freed immediately after extraction (streaming). Only one AST in memory at a time.
- **Vendor**: in `boundary` mode (default), vendor classes are `external` nodes (leaves) — their files are not analyzed.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Composer

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance82

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

91d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11473997?v=4)[DeGraciaMathieu](/maintainers/DeGraciaMathieu)[@DeGraciaMathieu](https://github.com/DeGraciaMathieu)

---

Top Contributors

[![DeGraciaMathieu](https://avatars.githubusercontent.com/u/11473997?v=4)](https://github.com/DeGraciaMathieu "DeGraciaMathieu (7 commits)")

---

Tags

analyticsarchitecturephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/degraciamathieu-php-dep/health.svg)

```
[![Health](https://phpackages.com/badges/degraciamathieu-php-dep/health.svg)](https://phpackages.com/packages/degraciamathieu-php-dep)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9184.1M24](/packages/phparkitect-phparkitect)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54642.4k4](/packages/jolicode-castor)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136400.8k14](/packages/rector-rector-src)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4753.9M23](/packages/coenjacobs-mozart)[brianhenryie/strauss

Prefixes dependencies namespaces so they are unique to your plugin

186406.5k30](/packages/brianhenryie-strauss)

PHPackages © 2026

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