This little tool helps you visualize the cohesion of a class by showing the relationship between its methods and properties. It helps you to follow the SRP (Single Responsiblity Principle) by showing you how a class could be split up.
class Example
{
private $a;
private $b;
private $c;
public function a(): void
{
$this->a;
}
public function ab(): void
{
$this->a;
$this->b;
}
public function c(): void
{}
}
composer require bigwhoop/php-extract-class-components
vendor/bin/php-class-components-extractor Path/To/Your/Class.php
Check the -h
option for more information:
Usage: ./class-components-extractor [options] input
Arguments:
input Path to a PHP file or - to use STDIN
Options:
-h --help Shows this help
-f --format <format> Output format to use. One of the followwing:
json JSON (default)
text Human-readable representation
graphviz Graphviz's graph description language
Examples:
./class-components-extractor file.php
./class-components-extractor file.php > components.json
./class-components-extractor --format text file.php
./class-components-extractor --format graphviz file.php | dot -Tpng -o diagram.png
cat file.php | ./class-components-extractor --graphviz - | dot -Tpng -o diagram.png
vendor/bin/phpstan
vendor/bin/phpunit