10
14

More than 3 years have passed since last update.

PHPのソースコードからクラス図を自動生成

Last updated at Posted at 2020-09-07

PHUMLでPHPのクラス図を画像で作成する

PHPSTORMにはクラス図を作成してくれる機能がついているそうですがお家環境にはPHPSTORM入っていないのでクラス図を自動生成してくれるツールを探していてphumlというツールを発見しました。
環境はUbuntu18.04LTSです。

インストール

https://github.com/jakobwesthoff/phuml
からダウンロードして適当な場所に展開しましょう。
僕は~/.localにphumlとして展開しました。
これで実行できるようになりました。

$php ~/.local/phuml/src/app/phuml
phUML Version 0.2 (Jakob Westhoff <jakob@php.net>)
Usage: phuml [-h|-l] [OPTIONS] <DIRECTORY> <PROCESSOR> [PROCESSOR OPTIONS] ... <OUTFILE>

Commands:
    -h      Display this help text
    -l      List all available processors

Options: 
    -r      Scan given directorie recursively

Example:
    phuml -r ./ -graphviz -createAssociations false -neato out.png

    This example will scan the current directory recursively for php files.
    Send them to the "dot" processor which will process them with the option
    "createAssociations" set to false. After that it will be send to the neato
    processor and saved to the file out.png

僕は毎度入力するのしんどいのでシンボリックリンク貼っときました。

sudo ln -si ~/.local/phuml/src/app/phuml /usr/local/bin

あとは解析したいディレクトリに移動してサンプルにもある用に

phuml -r ./ -graphviz -createAssociations false -neato out.png

を実行して上げればOKです。
試しにlaravelのエコシステムの一つpassportのsrcディレクトリ内で実行してみました。

passport_src.png

ちゃんと表示できました!

10
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
14