PHPackages                             paglliac/dependency-analysis - 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. paglliac/dependency-analysis

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

paglliac/dependency-analysis
============================

Library for static analysis modules dependencies in php projects

v0.1.2(4y ago)1340[4 issues](https://github.com/paglliac/php-dependency-analysis/issues)MITPHPPHP &gt;=7.4

Since Jul 20Pushed 4y ago1 watchersCompare

[ Source](https://github.com/paglliac/php-dependency-analysis)[ Packagist](https://packagist.org/packages/paglliac/dependency-analysis)[ RSS](/packages/paglliac-dependency-analysis/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (2)Versions (6)Used By (0)

PHP Dependency analyzer
=======================

[](#php-dependency-analyzer)

 [![Build Status](https://github.com/paglliac/php-dependency-analysis/actions/workflows/php.yml/badge.svg)](https://github.com/paglliac/php-dependency-analysis/actions)

PHP DA is tool for check and support dependencies inside your project clear.

For example:

- You have project with 3 root namespaces: Domain, Application, Infrastructure
- You want to be sure dependencies in your project defined as graph

```
[
    'dependencies' => [
        '\Domain' => null,
        '\Application' => ['\Domain'],
        '\Infrastructure' => ['\Domain', '\Application']
    ]
];
```

That means all classes from **Domain** namespace should use only classes from this namespace, and possibly vendor (it s configured).

All classes from **Application** can use classes from **Domain** and **Application** namespaces, but not from **Infrastructure**, etc

If some classes using dependencies not satisfied defined dependency graph, you give errors in report:

```
Have been analyzed 4 files
You have dependency problems in 2 files in your project:

Class \Application\TrackingService have errors:
    - Class \Application\TrackingService using class \Infrastructure\ShipImplementation which not satisfy dependency graph

Class \Domain\Cargo have errors:
    - Class \Domain\Cargo using class \Application\TrackingService which not satisfy dependency graph
    - Class \Domain\Cargo using class \Infrastructure\ShipImplementation which not satisfy dependency graph

```

Use cases
---------

[](#use-cases)

It can be useful in some cases for example:

- You want to extract part of your application in separate service, you define valid dependencies and run php-da for investigate workload
- You want to support low coupling in your application, you define valid dependencies and run php-da on your CI server for every MR, only for changed files
- You want to make visible structure changes of your application for all developers, now it is visible in php-da config

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

[](#quick-start)

Install library using composer

```
composer require paglliac/dependency-analysis

```

### Configuration

[](#configuration)

Add configuration file `config.php` to root of your project :

```
return [
    /**
     * REQUIRED
     * Dependencies Graph
     *
     * Description of valid dependencies in project
     *
     * This config means
     *
     * Package (every class in namespace) \Domain can use only classes from namespace \Domain or vendor dependencies
     * Package \Application can use only classes from namespaces \Domain, \Application or vendor dependencies
     * Package \Infrastructure can use only classes from namespaces \Domain, \Application, \Infrastructure or vendor dependencies
     */
    'dependencies' => [
        '\Domain' => null,
        '\Application' => ['\Domain'],
        '\Infrastructure' => ['\Domain', '\Application']
    ],

    /**
     * REQUIRED
     * Source path where dependencies will be analyzed
     */
    'path' => __DIR__,

    /**
     * OPTIONAL
     *
     * Make available to use vendor dependencies in whole project
     *
     * true - all project classes can use vendor dependencies
     * false - all project can not use vendor dependencies
     */
    'skip_vendor_dir' => true,

    /**
     * OPTIONAL
     * Flag that define how to do when some files placed in namespaces not presented in Dependencies Graph
     *
     * true - mark class as having incorrect dependencies
     * false - skip this file
     *
     * For example, in directory we have namespace \SomeNamespace with class \SomeNamespace\SomeClass
     * if flag is true, it will be marked as incorrect file, if flag is true, this file wil be marked as correct
     */
    'fail_on_non_presented_namespace' => false,

    /**
     * OPTIONAL
     * Flag for php parser, correct values:
     *
     * PhpParser\ParserFactory::PREFER_PHP7 - 1 (default)
     * PhpParser\ParserFactory::PREFER_PHP5 - 2
     * PhpParser\ParserFactory::ONLY_PHP7 - 3
     * PhpParser\ParserFactory::ONLY_PHP5 - 4
     */
    'php_version' => PhpParser\ParserFactory::PREFER_PHP7,

    /**
     * OPTIONAL
     *
     * List of allowed files extensions, all files with other extensions will be skipped from analysis
     *
     * Default - ['php']
     */
    'allowed_extensions' => ['php']
];
```

### Running

[](#running)

Run dependency validation:

```
/vendor/bin/php-da -c config.php [files filter]

```

Options:

- `-c` or `--config` is required option with the relative path to config file

Arguments:

- `[files filter]` list of files for analysis, it's useful to use in CI combine with --diff

### Example of output

[](#example-of-output)

```
Have been analyzed 4 files
You have dependency problems in 2 files in your project:

Class \Application\TrackingService have errors:
    - Class \Application\TrackingService using class \Infrastructure\ShipImplementation which not satisfy dependency graph

Class \Domain\Cargo have errors:
    - Class \Domain\Cargo using class \Application\TrackingService which not satisfy dependency graph
    - Class \Domain\Cargo using class \Infrastructure\ShipImplementation which not satisfy dependency graph

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Every ~3 days

Total

5

Last Release

1796d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c87a6ba7f909b37c786e738511d30ae722c1df9ce68dd5b5c6db9c0c02756ae9?d=identicon)[Gangster Elephant](/maintainers/Gangster%20Elephant)

---

Top Contributors

[![paglliac](https://avatars.githubusercontent.com/u/4892146?v=4)](https://github.com/paglliac "paglliac (51 commits)")

---

Tags

analysisphpstatic-analysis

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paglliac-dependency-analysis/health.svg)

```
[![Health](https://phpackages.com/badges/paglliac-dependency-analysis/health.svg)](https://phpackages.com/packages/paglliac-dependency-analysis)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M118](/packages/deptrac-deptrac)[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

6003.7M103](/packages/roave-backward-compatibility-check)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4814.0M25](/packages/coenjacobs-mozart)[v.chetkov/php-clean-architecture

PHP Clean Architecture

14661.1k](/packages/vchetkov-php-clean-architecture)

PHPackages © 2026

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