sweetchuck / cdd
Circular dependency detector
Installs: 273 243
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/sweetchuck/cdd
Requires
- php: >=8.2
Requires (Dev)
- ext-json: *
- codeception/codeception: ^5.0
- codeception/module-asserts: ^3.0
- consolidation/robo: ^4.0
- nuvoleweb/robo-config: ^3.0
- phpmd/phpmd: ^2.9
- phpstan/phpstan: 1.11.x-dev
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.3
- sweetchuck/git-hooks: 2.x-dev
- sweetchuck/robo-git: 3.x-dev
- sweetchuck/robo-phpcs: 3.x-dev
- sweetchuck/robo-phpmd: 3.x-dev
- sweetchuck/robo-phpstan: 2.x-dev
- symfony/error-handler: ^5.4 || ^6.0
README
A lightweight PHP library for detecting circular dependencies in complex systems. This library provides a simple and efficient API to identify loops and cycles within dependency chains, making it an essential tool for maintaining clean architecture and preventing infinite loops in your applications.
When to Use
This library is ideal for projects that need to:
- Validate dependency graphs - Ensure there are no circular references in your dependency structures
- Build system management - Detect cycles in build task dependencies to prevent infinite loops
- Module/package validation - Verify that plugin systems or modular architectures don't have circular imports
- Code analysis tools - Power dependency analysis features in linters and static analysis tools
- Architecture enforcement - Maintain strict layered architecture by preventing unwanted circular dependencies
- Plugin systems - Validate plugin dependencies before loading them
Features
- Zero runtime dependencies - lightweight and dependency-free
- Detects complex cycles - identifies loops of any depth
- Returns cycle paths - shows exactly which items form the cycle
Usage
<?php declare(strict_types = 1); use Sweetchuck\cdd\CircularDependencyDetector; $detector = new CircularDependencyDetector(); $items = [ // Item "a" has no any dependencies. 'a' => [], // Item "b" depends on "c" and "d". 'b' => ['c', 'd'], // Item "c" has no any dependencies. 'c' => [], // Item "d" has no any dependencies. 'd' => [], ]; $loops = $detector->detect($items); /** * $loops = []; */ var_dump($loops); $items = [ // Item "a" depends on "b". 'a' => ['b'], // Item "b" depends on "a". 'b' => ['a'], ]; $loops = $detector->detect($items); /** * $loops = [ * 'a|b' => ['b', 'a', 'b'], * ]; */ var_dump($loops); $items = [ // Item "a" depends on "b". 'a' => ['b'], // Item "b" depends on "c". 'b' => ['c'], // Item "c" depends on "a". 'c' => ['a'], ]; $loops = $detector->detect($items); /** * $loops = [ * 'a|b|c' => ['c', 'a', 'b', 'c'], * ]; */ var_dump($loops);