Skip to content

This little tool helps you visualize the cohesion of a class by showing the relationship between its methods and properties. It helps you following the SRP (Single Responsiblity Principle) by showing you how a class could be split up.

License

Notifications You must be signed in to change notification settings

bigwhoop/php-extract-class-components

Repository files navigation

php-class-components-extractor

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
    {}
}

Example

How to install

composer require bigwhoop/php-extract-class-components

How to use

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

Contributing

How to run tests

vendor/bin/phpstan
vendor/bin/phpunit

About

This little tool helps you visualize the cohesion of a class by showing the relationship between its methods and properties. It helps you following the SRP (Single Responsiblity Principle) by showing you how a class could be split up.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages