{"id":13593520,"url":"https://github.com/smeghead/php-class-diagram","last_synced_at":"2025-05-16T15:07:17.841Z","repository":{"id":39165701,"uuid":"423499730","full_name":"smeghead/php-class-diagram","owner":"smeghead","description":"A CLI tool that parses the PHP source directory and generates PlantUML class diagram scripts as output.","archived":false,"fork":false,"pushed_at":"2025-02-25T11:01:17.000Z","size":11347,"stargazers_count":144,"open_issues_count":3,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-19T21:02:05.957Z","etag":null,"topics":["classdiagram","composer-library","php","plantuml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smeghead.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-11-01T14:38:43.000Z","updated_at":"2025-04-16T05:01:01.000Z","dependencies_parsed_at":"2024-01-12T20:47:34.399Z","dependency_job_id":"d6c94ef0-5ec5-4782-97f4-d9821c34e14b","html_url":"https://github.com/smeghead/php-class-diagram","commit_stats":{"total_commits":170,"total_committers":2,"mean_commits":85.0,"dds":"0.12352941176470589","last_synced_commit":"4ea6e81004ceaa11e67fad85799b6f4e7df733bc"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smeghead%2Fphp-class-diagram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smeghead%2Fphp-class-diagram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smeghead%2Fphp-class-diagram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smeghead%2Fphp-class-diagram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smeghead","download_url":"https://codeload.github.com/smeghead/php-class-diagram/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553959,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classdiagram","composer-library","php","plantuml"],"created_at":"2024-08-01T16:01:21.125Z","updated_at":"2025-05-16T15:07:17.819Z","avatar_url":"https://github.com/smeghead.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# php-class-diagram\n\nA CLI tool that parses the PHP source directory and generates PlantUML class diagram scripts as output.\n\n![Testing](https://github.com/smeghead/php-class-diagram/actions/workflows/php.yml/badge.svg?event=push) [![Latest Stable Version](https://poser.pugx.org/smeghead/php-class-diagram/v)](https://packagist.org/packages/smeghead/php-class-diagram) [![Total Downloads](https://poser.pugx.org/smeghead/php-class-diagram/downloads)](https://packagist.org/packages/smeghead/php-class-diagram) [![Latest Unstable Version](https://poser.pugx.org/smeghead/php-class-diagram/v/unstable)](https://packagist.org/packages/smeghead/php-class-diagram) [![License](https://poser.pugx.org/smeghead/php-class-diagram/license)](https://packagist.org/packages/smeghead/php-class-diagram) [![PHP Version Require](https://poser.pugx.org/smeghead/php-class-diagram/require/php)](https://packagist.org/packages/smeghead/php-class-diagram)\n\n## Features\n\n * ♻️ Generating class diagrams from source code contributes to continuous design improvement.\n * 🔖  It produces expressive class diagrams with a focus on namespaces and relationships.\n * 🌐 Diagrams are interactive hypermedia tools, allowing you to click on class boxes to navigate directly to the source code, enhancing understanding both visually and interactively.\n * 🔧 This simple CLI tool is easy to use.\n * 💡 Additionally, it can generate a package relationship diagram to visualize dependencies on external namespaces.\n\n## What is PlantUML\n\n\u003e [PlantUML - Wikipedia](https://en.wikipedia.org/wiki/PlantUML)\n\u003e PlantUML is an open-source tool allowing users to create diagrams from a plain text language. Besides various UML diagrams, PlantUML has support for various other software development related formats (such as Archimate, Block diagram, BPMN, C4, Computer network diagram, ERD, Gantt chart, Mind map, and WBD), as well as visualisation of JSON and YAML files.\n\n## Hypermedia Feature\n\nOne of the standout features of this tool is the ability to generate class diagrams with clickable links that navigate directly to the source code of those classes. This transforms the diagrams into interactive hypermedia tools, enhancing the understanding of the source code visually and interactively.\n\nTo enable this feature, generate the diagrams in SVG format and use the `--svg-topurl` option to specify the base URL for the links:\n\n```shell\n$ vendor/bin/php-class-diagram \\\n    --svg-topurl='https://github.com/your-username/your-repo/blob/main/path/to/source' \\\n    path/to/php/files\n```\n\nTo embed the SVG diagrams in HTML while preserving the clickable links, use the `embed` or `object` tags instead of `img`. Here’s an example:\n\n```html\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003ePHP Class Diagram\u003c/title\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003cstyle\u003e\n        embed {\n            max-width: 100%;\n            max-height: 200%;\n            width: auto;\n            height: auto;\n        }\n    \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cembed type=\"image/svg+xml\" src=\"php-class-diagram.svg\"/\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThis ensures that the SVG image is responsive and the hyperlinks remain functional.\n\n[Hypermedia example](https://smeghead.github.io/php-class-diagram/hyper-media.html)\n\n## Dogfooding\n\n### php-class-diagram class diagram (linked SVG file)\n\n\u003cimg src=\"docs/images/dogfood.svg\"\u003e\n\n### php-class-diagram class diagram without fields and methods\n\nIf your analysis primarily focuses on the relationships between classes, a simpler notation may be more appropriate.\n\n![dogfood class diagram image.](docs/images/dogfood-model.png)\n\n### php-class-diagram package related diagram\n\nVisualizing package relationships can uncover critical design issues.\n\n![dogfood package related diagram image.](docs/images/dogfood-package.png)\n\n## Install\n\n### From DockerHub\n\nYou can utilize a Docker image that includes php-class-diagram and PlantUML from the following URL.\n\n * https://hub.docker.com/r/smeghead7/php-class-diagram\n\n### From Composer\n\n```bash\n$ mkdir example\n$ cd example\n$ composer init\n$ composer require --dev smeghead/php-class-diagram\n```\n\nNow, you can execute `./vendor/bin/php-class-diagram`.\nFor instance, try to display help message.\n\n```bash\n$ vendor/bin/php-class-diagram --help\nusage: php-class-diagram [OPTIONS] \u003ctarget php source directory\u003e\n\nA CLI tool that parses the PHP source directory and generates PlantUML class diagram scripts as output.\n\nOPTIONS\n  -h, --help                       show this help page.\n  -v, --version                    show version.\n      --class-diagram              output class diagram script. (default)\n      --package-diagram            output package diagram script.\n      --division-diagram           output division diagram script.\n      --jig-diagram                output class diagram and package diagram script.\n      --enable-class-properties    describe properties in class diagram. (default)\n      --disable-class-properties   not describe properties in class diagram.\n      --enable-class-methods       describe methods in class diagram. (default)\n      --disable-class-methods      not describe methods in class diagram.\n      --enable-class-name-summary  describe classname with Class summary of document comment. (default)\n      --disable-class-name-summary describe classname without Class summary of document comment.\n      --hide-private               hide private properties and methods.\n      --hide-private-properties    hide private properties.\n      --hide-private-methods       hide private methods.\n      --svg-topurl='url'           Specifies the top URL when displaying the class as a link when outputting in SVG format.\n      --header='header string'     additional header string. You can specify multiple header values.\n      --include='wildcard'         include target file pattern. (default: `*.php`) You can specify multiple include patterns.\n      --exclude='wildcard'         exclude target file pattern. You can specify multiple exclude patterns.\n      --rel-target-from='classes'  comma separated list of classes to filter dependencies from\n      --rel-target-to='classes'    comma separated list of classes to filter dependencies to\n      --rel-target='classes'       comma separated list of classes to filter dependencies from or to. this option overrides\n                                   --rel-target-from and --rel-target-to if set.\n      --rel-target-depth=integer   max depth of dependencies to show when using --from or --to filters\n```\n\n## How to execute\n\n### Class Diagram\n\nIf there are three PHP source files in the directory test/fixtures/no-namespace each with a TYPE comment,\n\n * php source files.\n\n```\n└─test\n    └─fixtures\n        └─no-namespace\n            └─product\n                    Product.php\n                    Name.php\n                    Price.php\n```\n\n * Product.php\n```php\n\u003c?php\nclass Product {\n    /** @var Name   product name. */\n    private $name;\n    /** @var Price  price of product. */\n    private $price;\n}\n```\n\n * Name.php\n```php\n\u003c?php\nclass Name {\n    /** @var string  name. */\n    private $name;\n}\n```\n\n * Price.php\n```php\n\u003c?php\nclass Price {\n    /** @var int  price. */\n    private int $price;\n}\n```\n\nExecuting `php-class-diagram` will output the PlantUML script.\n\n```bash\n$ vendor/bin/php-class-diagram test/fixtures/no-namespace\n@startuml class-diagram\n  package product as product {\n    class \"Price\" as product_Price {\n      -price : int\n    }\n    class \"Name\" as product_Name {\n      -name : string\n    }\n    class \"Product\" as product_Product {\n      -name : Name\n      -price : Price\n      +method1(param1)\n    }\n  }\n  product_Product ..\u003e product_Name\n  product_Product ..\u003e product_Price\n  product_Product ..\u003e product_Product\n@enduml\n```\n\nUse PlantUML to convert the PlantUML script to an image.\n\n![PlantUML output image.](docs/images/output.png)\n\n\n#### option `header`\n\nYou can specify the string to be output to the PlantUML header.\n\n```bash\n$ vendor/bin/php-class-diagram \\\n    --header='title \"This is the class diagram\"' \\\n    path/to/src\n```\n\n#### option `include`\n\nYou can add patterns to specify the target files for processing.\n\n```bash\n$ vendor/bin/php-class-diagram \\\n    --include='*.php' \\\n    --include='*.php4' \\\n    path/to/src\n```\n\n#### option `exclude`\n\nYou can specify patterns to exclude files from the processing. If you want to ignore a folder, you must specify the relative path to the target php source directory.\n\n```bash\n$ vendor/bin/php-class-diagram \\\n    --exclude='test' \\\n    --exclude='*Exception.php' \\\n    path/to/src\n```\n\n#### option `rel-target`\n\nIf there are a very large number of target classes, the class diagram will be cumbersome and difficult to understand.\nIn such a case, you can specify the classes you want to study in the `--rel-target` field to generate a class diagram for only the related classes.\nBy using `--rel-target-from` and `--rel-target-to`, it is also possible to further narrow down the list according to the direction of dependencies.\n\n```bash\n$ vendor/bin/php-class-diagram \\\n    --rel-target=Entry \\\n    --rel-target-depth=3 \\\n    path/to/src\n```\n\n```bash\n$ vendor/bin/php-class-diagram \\\n    --rel-target-from=Entry \\\n    --rel-target-depth=3 \\\n    path/to/src\n```\n\n### Package Diagram\n\nYou can visualize package dependencies by creating a package relationship diagram using php-class-diagram.\n\n```bash\n$ vendor/bin/php-class-diagram --package-diagram test/fixtures/dependency-loops\n@startuml package-related-diagram\n  package hoge.fuga as ROOT {\n    package product as product {\n      package attribute as product.attribute {\n      }\n      package config as product.config {\n      }\n    }\n  }\n  product --\u003e product.attribute\n  product \u003c-[#red,plain,thickness=4]-\u003e product.config\n@enduml\n```\n\nPackages that depend on each other are undesirable.\nIf the tool detects such dependencies, it will issue a warning with a thick red line.\n\n![PlantUML output image.](docs/images/output-package-dep-loop.png)\n\n\n![PlantUML output image.](docs/images/output-package.png)\n\n\n### Division Diagram\n\nIf you are utilizing the Enum feature introduced in PHP 8.1, you can generate the division diagram.\nVisualizing the divisions employed in the program can be beneficial for research and design purposes.\n\n```bash\n$ bin/php-class-diagram --division-diagram test/fixtures/enum/ \n@startuml division-diagram\n  card Suit #ccffcc [\n    Suit\n    \u003cb\u003eスート\u003c/b\u003e\n    ====\n    Hearts\n    \u003cb\u003eハート\u003c/b\u003e\n    ----\n    Diamonds\n    \u003cb\u003eダイヤ\u003c/b\u003e\n    ----\n    Clubs\n    \u003cb\u003eクローバー\u003c/b\u003e\n    ----\n    Spades\n    \u003cb\u003eスペード\u003c/b\u003e\n  ]\n  package Sub as Sub {\n    card Status #ffcccc [\n      Status\n      \u003cb\u003eゲームのステータス\u003c/b\u003e\n      ====\n      Player\n      \u003cb\u003eプレイヤーのターン\u003c/b\u003e\n      ----\n      Computer\n      \u003cb\u003eコンピュータのターン\u003c/b\u003e\n      ----\n      GameSet\n      \u003cb\u003eゲーム終了\u003c/b\u003e\n    ]\n    card MyExceptionCase #ccccff [\n      MyExceptionCase\n      ====\n      InvalidMethod\n      ----\n      InvalidProperty\n      ----\n      Timeout\n    ]\n    card Size #ccffff [\n      Size\n      ====\n      Small\n      ----\n      Medium\n      ----\n      Large\n    ]\n  }\n@enduml\n```\n\n\n![PlantUML output image.](docs/images/output-division.png)\n\n## Extension for Visual Studio Code\n\nThis VSCode extension allows you to generate and view class diagram scripts using php-class-diagram directly from the file explorer's folder context menu.\n\n[VSCode extension](https://marketplace.visualstudio.com/items?itemName=smeghead7.php-class-diagram)\n\n\n## GitHub Actions support\n\nThe following repository provides actions for generating class diagrams using php-class-diagram in GitHub Actions workflows.\n\n[smeghead/php-class-diagram-gh-action](https://github.com/smeghead/php-class-diagram-gh-action)\n\n\n## Development\n\n### Open shell\n\n```bash\ndocker compose build\ndocker compose run --rm php_cli bash\n```\n\n### install dependencies\n\n```bash\ncomposer install\n```\n\n### execute tests\n\n```bash\ncomposer test\n```\n\n## CONTRIBUTING\n\nBoth Issues and Pull Requests are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmeghead%2Fphp-class-diagram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmeghead%2Fphp-class-diagram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmeghead%2Fphp-class-diagram/lists"}