bigwhoop/php-extract-class-components

Extract components (methods and properties interacting with each other) from a PHP class. The result can be visualized and aid in splitting up classes.

2.0.0 2024-03-10 19:57 UTC

This package is auto-updated.

Last update: 2024-05-10 20:47:02 UTC


README

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