smeghead/php-class-diagram

A CLI tool that parses the PHP source directory and outputs PlantUML scripts.

v0.0.6 2021-11-27 04:51 UTC

This package is auto-updated.

Last update: 2021-11-27 04:54:10 UTC


README

A CLI tool that parses the PHP source directory and outputs PlantUML class diagram scripts.

Features

  • Generating class diagrams from source code helps improve continuous design.
  • Generates expressive class diagrams with an emphasis on namespaces and relationships.
  • A simple CLI tool that is easy to handle.
  • It is also possible to output a package relationship diagram that visualizes the dependency on the external namespace.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

php-class-diagram class diagram

dogfood class diagram image.

php-class-diagram package related diagram

dogfood package related diagram image.

Install

From DockerHub

You can use docker image includes php-class-diagram and plantuml, from below URL.

From Composer

$ mkdir sample
$ cd sample
$ composer init
$ composer require smeghead/php-class-diagram

you can execute ./vendor/bin/php-class-diagram. for instance, try to display help message.

$ vendor/bin/php-class-diagram --help
usage: php-class-diagram [OPTIONS] <target php source directory>

A CLI tool that parses the PHP source directory and outputs PlantUML class diagram scripts.

OPTIONS
  -h, --help                     show this help page.
      --class-diagram            output class diagram script. (default)
      --package-diagram          output package diagram script.
      --jig-diagram              output class diagram and package diagram script.
      --enable-class-properties  describe properties in class diagram.
      --disable-class-properties not describe properties in class diagram.
      --enable-class-methods     describe methods in class diagram.
      --disable-class-methods    not describe methods in class diagram.
      --php5                     parse php source file as php5.
      --php7                     parse php source file as php7.
      --php8                     parse php source file as php8. (not suppoted)

How to execute

When three php source files that TYPE commented exist in test/fixtures/no-namespace,

  • php source files.
└─test
    └─fixtures
        └─no-namespace
            └─product
                    Product.php
                    Name.php
                    Price.php
  • Product.php
<?php
class Product {
    /** @var Name   product name. */
    private $name;
    /** @var Price  price of product. */
    private $price;
}
  • Name.php
<?php
class Name {
    /** @var string  name. */
    private $name;
}
  • Price.php
<?php
class Price {
    /** @var int  price. */
    private int $price;
}

To execute php-class-diagram will print PlantUML script.

$ vendor/bin/php-class-diagram test/fixtures/no-namespace
@startuml
  package product as product <<Rectangle>> {
    class product.Price
    class product.Name
    class product.Product
  }
  product.Product ..> product.Name
  product.Product ..> product.Price
@enduml

Use PlnatUML to convert the PlantUML script to an image.

PlantUML output image.

Development

Open shell

docker-compose build
docker-compose run --rm php_cli bash

install dependencies

composer install

execute tests

composer test