PHP Classes

How to Generate a PHP Dependency Graph to Determine the Stability of a Project Using the Tool PHP Class Dependencies Analyzer: Analyze the dependencies of project classes

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-11-03 (Yesterday) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
php-class-dependenci 1.0The PHP License8Tools, Language, PHP 8
Description 

Author

This package can analyze the dependencies of project classes.

It provides a command-line console tool to run from the to check the class files in a given directory.

The tool can generate a report in the form of a graph image that shows the dependencies of the classes that were found.

Picture of DeGraciaMathieu
  Performance   Level  
Name: DeGraciaMathieu <contact>
Classes: 22 packages by
Country: France France
Innovation award
Innovation award
Nominee: 16x

Winner: 2x

Documentation

<p align="center"> <img src="https://github.com/DeGraciaMathieu/php-smelly-code-detector/blob/master/arts/robot.png" width="250"> </p>

php-class-dependencies-analyzer

testing

> ?? For French developers, an article on Laravel France explores these stable dependency concepts.

Phar

This tool is distributed as a PHP Archive (PHAR):

wget https://github.com/DeGraciaMathieu/php-class-dependencies-analyzer/raw/main/builds/class-dependencies-analyzer

php class-dependencies-analyzer --version

Why

Inevitably, in an object-oriented project, classes will depend on each other.

These dependencies generate instability that can be measured with the following formula:

Instability = Efferent / (Afferent + Efferent)

Afferent coupling represents the number of components that depend on a given component, while efferent coupling counts the number of dependencies a given component has.

<img src='https://cdn.laravel-france.com/images/pictures/6aa50c00-414c-4817-928d-c67d1bf996e0.png'>

Instability ranges between 0 and 1, where 0 represents a fully stable class and 1 represents a fully unstable class.

Stable class has few dependencies but is depended on by many components. Therefore, a stable class is critical to the project and must be reliable and well-tested.

An unstable class has many dependencies but few components depend on it. Therefore, it?s easier to modify, but it?s more likely to be affected by changes in its dependencies. It is recommended to monitor the dependencies of an unstable component and replace those that are even more unstable with an abstraction.

It?s important to manage these dependencies between classes to maintain maintainable, modular, and easily testable code.

This tool allows you to:

  • Detect classes with a high coupling instability rate
  • Detect cyclic dependencies among a set of classes
  • Detect fragile dependencies between classes

Visualizing Instability

To visualize the instability and coupling of your classes:

php class-dependencies-analyzer analyze ./path/to/project

?? To obtain accurate results, it is important to analyze your entire codebase, use the --only=* or --exclude=* options to filter the results.

php class-dependencies-analyzer analyze app --only=App\\Domain,Infrastructure
php class-dependencies-analyzer analyze app --exclude=Models

For visualizing the results in a graph, you can use the --graph option:

php class-dependencies-analyzer analyze app --only=App\\Domain --graph

<img style="width: 50%;" src='/arts/graph.png'>

Detecting Cyclic Dependencies

A dependency cycle is a class that depends on itself through its dependencies.

<img src='https://cdn.laravel-france.com/images/pictures/34ddeac2-d9ac-4ebb-a54c-48f7940945ca.png'>

This violates the acyclic dependencies principle, it can be a sign of a bad design and reveal an ensemble of components difficult to maintain and evolve.

php class-dependencies-analyzer cyclic ./path/to/project

> You can filter the results using the --only=* or --exclude=* options.

Detecting Fragile Dependencies

A fragile dependancy is a class that depends on a class that is more unstable than it.

It can be a sign of a bad design and an indicator of a class that can suffer from side effects of its dependencies.

The first class will be sensitive to any changes made to the second class and will experience side effects.

<img src='https://cdn.laravel-france.com/images/pictures/c80b59f3-ffad-4609-9364-f8efa4e62c9a.png'>

These dependencies can generate bugs and difficulties in evolution.

php class-dependencies-analyzer weakness ./path/to/project

To filter results based on an instability delta, you can use the --min-delta option.

php class-dependencies-analyzer weakness ./path/to/project --min-delta=0.1

The delta corresponds to the difference in stability between a class and one of its dependencies. The greater this difference, the more likely the first component is to suffer from side effects caused by its unstable dependency.

> You can filter the results using the --only=* or --exclude=* options.

> [!TIP] > Other analysis tools are available.


  Files folder image Files (112)  
File Role Description
Files folder image.github (1 directory)
Files folder imageapp (5 directories)
Files folder imagearts (1 file)
Files folder imagebootstrap (2 files)
Files folder imageconfig (3 files)
Files folder imageresources (1 directory)
Files folder imagetests (3 files, 3 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file box.json Data Auxiliary data
Plain text file class-dependencies-analyzer Class Class source
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (112)  /  .github  
File Role Description
Files folder imageworkflows (2 files)

  Files folder image Files (112)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file build.yml Data Auxiliary data
  Accessible without login Plain text file testing.yml Data Auxiliary data

  Files folder image Files (112)  /  app  
File Role Description
Files folder imageApplication (3 directories)
Files folder imageDomain (5 directories)
Files folder imageInfrastructure (2 directories)
Files folder imagePresenter (1 directory)
Files folder imageProviders (1 file, 1 directory)

  Files folder image Files (112)  /  app  /  Application  
File Role Description
Files folder imageAnalyze (6 files)
Files folder imageCyclic (5 files)
Files folder imageWeakness (5 files)

  Files folder image Files (112)  /  app  /  Application  /  Analyze  
File Role Description
  Plain text file AnalyzeAction.php Class Class source
  Plain text file AnalyzePresenter.php Class Class source
  Plain text file AnalyzeRequest.php Class Class source
  Plain text file AnalyzeResponse.php Class Class source
  Plain text file AnalyzeResponseMapper.php Class Class source
  Plain text file ResponseMapper.php Class Class source

  Files folder image Files (112)  /  app  /  Application  /  Cyclic  
File Role Description
  Plain text file CyclicAction.php Class Class source
  Plain text file CyclicPresenter.php Class Class source
  Plain text file CyclicRequest.php Class Class source
  Plain text file CyclicResponse.php Class Class source
  Plain text file CyclicResponseMapper.php Class Class source

  Files folder image Files (112)  /  app  /  Application  /  Weakness  
File Role Description
  Plain text file WeaknessAction.php Class Class source
  Plain text file WeaknessPresenter.php Class Class source
  Plain text file WeaknessRequest.php Class Class source
  Plain text file WeaknessResponse.php Class Class source
  Plain text file WeaknessResponseMapper.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  
File Role Description
Files folder imageAggregators (1 file)
Files folder imageEntities (1 file)
Files folder imagePorts (2 directories)
Files folder imageServices (4 files)
Files folder imageValueObjects (3 files)

  Files folder image Files (112)  /  app  /  Domain  /  Aggregators  
File Role Description
  Plain text file DependencyAggregator.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  /  Entities  
File Role Description
  Plain text file ClassDependencies.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  /  Ports  
File Role Description
Files folder imageAggregators (1 file)
Files folder imageRepositories (1 file)

  Files folder image Files (112)  /  app  /  Domain  /  Ports  /  Aggregators  
File Role Description
  Plain text file FileAggregator.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  /  Ports  /  Repositories  
File Role Description
  Plain text file FileRepository.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  /  Services  
File Role Description
  Plain text file CyclicDependency.php Class Class source
  Plain text file Instability.php Class Class source
  Plain text file Stack.php Class Class source
  Plain text file Visited.php Class Class source

  Files folder image Files (112)  /  app  /  Domain  /  ValueObjects  
File Role Description
  Plain text file Coupling.php Class Class source
  Plain text file Dependencies.php Class Class source
  Plain text file Fqcn.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  
File Role Description
Files folder imageAnalyze (2 directories)
Files folder imageFile (2 directories)

  Files folder image Files (112)  /  app  /  Infrastructure  /  Analyze  
File Role Description
Files folder imageAdapters (1 directory)
Files folder imagePorts (1 file)

  Files folder image Files (112)  /  app  /  Infrastructure  /  Analyze  /  Adapters  
File Role Description
Files folder imageJerowork (3 files)

  Files folder image Files (112)  /  app  /  Infrastructure  /  Analyze  /  Adapters  /  Jerowork  
File Role Description
  Plain text file AnalyzerServiceAdapter.php Class Class source
  Plain text file CustomClassDependenciesParser.php Class Class source
  Plain text file NodeTraverserFactory.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  /  Analyze  /  Ports  
File Role Description
  Plain text file AnalyzerService.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  
File Role Description
Files folder imageAdapters (3 directories)
Files folder imagePorts (1 file)

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  /  Adapters  
File Role Description
Files folder imageAggregators (1 file)
Files folder imageDataTransferObjects (1 file)
Files folder imageRepositories (1 file)

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  /  Adapters  /  Aggregators  
File Role Description
  Plain text file FileAggregatorAdapter.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  /  Adapters  /  DataTransferObjects  
File Role Description
  Plain text file FileAdapter.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  /  Adapters  /  Repositories  
File Role Description
  Plain text file FileRepositoryAdapter.php Class Class source

  Files folder image Files (112)  /  app  /  Infrastructure  /  File  /  Ports  
File Role Description
  Plain text file File.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  
File Role Description
Files folder imageCommands (4 directories)

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  
File Role Description
Files folder imageAnalyze (1 file, 3 directories)
Files folder imageCyclic (1 file, 1 directory)
Files folder imageShared (3 files)
Files folder imageWeakness (1 file, 1 directory)

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  
File Role Description
Files folder imageFilters (6 files)
Files folder imageGraph (6 files, 2 directories)
Files folder imageSummary (6 files)
  Plain text file AnalyzeCommand.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Filters  
File Role Description
  Plain text file Depth.php Class Class source
  Plain text file Filter.php Class Class source
  Plain text file FilterFactory.php Class Class source
  Plain text file Metrics.php Class Class source
  Plain text file NullFilter.php Class Class source
  Plain text file TargetFilter.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Graph  
File Role Description
Files folder imageAdapters (1 directory)
Files folder imagePorts (2 files)
  Accessible without login Plain text file GraphEnums.php Aux. Configuration script
  Plain text file GraphPresenter.php Class Class source
  Plain text file GraphSettings.php Class Class source
  Plain text file GraphSettingsFactory.php Class Class source
  Plain text file GraphView.php Class Class source
  Plain text file GraphViewModel.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Graph  /  Adapters  
File Role Description
Files folder imageCytoscape (4 files)

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Graph  /  Adapters  /  Cytoscape  
File Role Description
  Plain text file CytoscapeGraph.php Class Class source
  Plain text file CytoscapeGraphMapper.php Class Class source
  Plain text file Edges.php Class Class source
  Plain text file Nodes.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Graph  /  Ports  
File Role Description
  Plain text file Graph.php Class Class source
  Plain text file GraphMapper.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Analyze  /  Summary  
File Role Description
  Plain text file SummaryMapper.php Class Class source
  Plain text file SummaryPresenter.php Class Class source
  Plain text file SummarySettings.php Class Class source
  Plain text file SummarySettingsFactory.php Class Class source
  Plain text file SummaryView.php Class Class source
  Plain text file SummaryViewModel.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Cyclic  
File Role Description
Files folder imageSummary (7 files)
  Plain text file CyclicCommand.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Cyclic  /  Summary  
File Role Description
  Plain text file CycleHelper.php Class Class source
  Plain text file CyclicPresenterMapper.php Class Class source
  Plain text file SummaryPresenter.php Class Class source
  Plain text file SummarySettings.php Class Class source
  Plain text file SummarySettingsFactory.php Class Class source
  Plain text file SummaryView.php Class Class source
  Plain text file SummaryViewModel.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Shared  
File Role Description
  Plain text file AbstractCommand.php Class Class source
  Plain text file ArrayFormatter.php Class Class source
  Plain text file NameFormatter.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Weakness  
File Role Description
Files folder imageSummary (6 files)
  Plain text file WeaknessCommand.php Class Class source

  Files folder image Files (112)  /  app  /  Presenter  /  Commands  /  Weakness  /  Summary  
File Role Description
  Plain text file SummaryPresenter.php Class Class source
  Plain text file SummarySettings.php Class Class source
  Plain text file SummarySettingsFactory.php Class Class source
  Plain text file SummaryView.php Class Class source
  Plain text file SummaryViewModel.php Class Class source
  Plain text file WeaknessPresenterMapper.php Class Class source

  Files folder image Files (112)  /  app  /  Providers  
File Role Description
Files folder imageCustom (1 file)
  Plain text file AppServiceProvider.php Class Class source

  Files folder image Files (112)  /  app  /  Providers  /  Custom  
File Role Description
  Plain text file CustomNodeTraverserFactory.php Class Class source

  Files folder image Files (112)  /  arts  
File Role Description
  Accessible without login Image file graph.png Icon Icon image

  Files folder image Files (112)  /  bootstrap  
File Role Description
  Accessible without login Plain text file app.php Example Example script
  Plain text file providers.php Class Class source

  Files folder image Files (112)  /  config  
File Role Description
  Plain text file app.php Class Class source
  Plain text file commands.php Class Class source
  Accessible without login Plain text file view.php Aux. Configuration script

  Files folder image Files (112)  /  resources  
File Role Description
Files folder imageviews (1 file)

  Files folder image Files (112)  /  resources  /  views  
File Role Description
  Accessible without login Plain text file graph.blade.php Aux. Configuration script

  Files folder image Files (112)  /  tests  
File Role Description
Files folder imageBuilders (2 files)
Files folder imageFeature (1 file)
Files folder imageUnit (1 file, 6 directories)
  Plain text file CreatesApplication.php Class Class source
  Plain text file Pest.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files (112)  /  tests  /  Builders  
File Role Description
  Plain text file ClassDependenciesBuilder.php Class Class source
  Plain text file DependencyAggregatorBuilder.php Class Class source

  Files folder image Files (112)  /  tests  /  Feature  
File Role Description
  Accessible without login Plain text file InspireCommandTest.php Aux. Configuration script

  Files folder image Files (112)  /  tests  /  Unit  
File Role Description
Files folder imageAggregators (1 file)
Files folder imageEntities (1 file)
Files folder imageFormatters (2 files)
Files folder imageHelpers (1 file)
Files folder imageServices (2 files)
Files folder imageValueObjects (2 files)
  Accessible without login Plain text file ExampleTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  Aggregators  
File Role Description
  Accessible without login Plain text file DependencyAggregatorTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  Entities  
File Role Description
  Accessible without login Plain text file ClassDependenciesTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  Formatters  
File Role Description
  Accessible without login Plain text file ArrayFormatterTest.php Example Example script
  Accessible without login Plain text file NameFormatterTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  Helpers  
File Role Description
  Accessible without login Plain text file CycleHelperTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  Services  
File Role Description
  Plain text file CyclicDependencyTest.php Class Class source
  Accessible without login Plain text file InstabilityTest.php Example Example script

  Files folder image Files (112)  /  tests  /  Unit  /  ValueObjects  
File Role Description
  Accessible without login Plain text file CouplingTest.php Example Example script
  Accessible without login Plain text file FqcnTest.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0