Automagically generate UML diagrams of your Laravel code.

Overview

Laravel To UML Example

Laravel UML Diagram Generator

Automagically generate UML diagrams of your Laravel code.

Installation

To install LTU via composer, run the command:

composer require andyabih/laravel-to-uml --dev

Usage

LTU will register the /uml route by default to a view that displays your UML graph.

You can configure the package and tweak it to fit your needs by publishing the config file using:

php artisan vendor:publish --provider="Andyabih\LaravelToUML\LaravelToUMLServiceProvider" --tag="config"

This will create a new laravel-to-uml.php file in your config folder.

Configuration

The configuration should hopefully be self-explanatory. You can change what type of classes get included in the diagram by changing the true|false boolean in the configuration file.

You can also change the styling of the diagram in the config. LTU uses nomnoml to generate the diagram, so more information about the different nomnoml styling properties can be found on their Github.

Exporting the diagram

nomnoml generates the diagram in a canvas, and you can simply right click & save the canvas to an image.

Importing requirements

Your classes must be imported using the use operator.

// This will work and generate everything properly.
use App\Models\Post;

// Using it directly in the code without the use operator won't.
$posts = \App\Models\Post::all();
Comments
  • "Undefined index: properties" in LaravelToUML.php

    I get an error "Undefined index: properties" pointing to LaravelToUML and getSource() which is:

    foreach ($c['properties'] as $property) {
        $properties[] = $property->name;
    }
    foreach ($c['methods'] as $method) {
        $methods[] = $method->name . "()";
    }
    $source = "[{$c['name']}";
    

    I tried to add ?? [] on the $c['properties'] so it would be empty if non-existing, but to no improvement, so I started investigated further and I found a big chunk of empty arrays in the $this->classes array, seemingly to be namespaces.

    I added this as first clause in the foreach:

    if ($c === []) {
        continue;
    }
    

    And the code started working. That would be an workaround of course, just helping the symptoms

    opened by orjanalmen 9
  • Files without a class in app directory throws exception

    Files without a class in app directory throws exception

    ReflectionException Class \App\Helpers does not exist

    app\helpers.php isn't a class but just some few helpful functions in the global namespace. I think that this shouldn't throw an error, but just ignore the file.

    opened by orjanalmen 2
  • Proper Enum handling

    Proper Enum handling

    For something like

    Enum code
    <?php
    
    namespace App\Enums;
    
    enum AppEnv: string
    {
        // The strings are given by Laravel's `.env` file. So, yes, short development and long prod. See `APP_ENV=local`.
        case Local = 'local';
        case Development = 'dev';
        case Production = 'prod';
        case Consolidation = 'cons';
    
        /**
         * Checks whether the APP_ENV matches the one passed
         *
         * @param AppEnv $appEnv
         * @return bool
         */
        public static function is(AppEnv $appEnv): bool
        {
            return config('app.env') === $appEnv->value;
        }
    
        /**
         * Checks whether the APP_ENV is in production mode
         *
         * @return bool
         */
        public static function isProduction(): bool
        {
            return self::is(self::Production);
        }
    
        /**
         * Checks whether the APP_ENV is in production mode
         *
         * @return bool
         */
        public static function isLocal(): bool
        {
            return self::is(self::Local);
        }
    }
    

    it however does not show the enum keys: image

    opened by luckydonald 0
  • Made relation regex non greedy

    Made relation regex non greedy

    It was failing with my models if they have something like ->select(['id', 'name']); after relation definition. For sure I can move it to next row but "non greedy way" looks more logical.

    opened by NickCoolii 0
  • ErrorException Undefined offset: 1

    ErrorException Undefined offset: 1

    Hi all, I just installed without any configuration change and got the following error: vendor/andyabih/laravel-to-uml/src/LaravelToUML.php:205

    image

    Quick debug shows that $matches is an empty array. [] The $relationship was "hasManyThrough". In my specific case the Model had the following:

      56 => "return $this->hasManyThrough("
      57 => "'App\Models\Status\Status',"
      58 => "'App\Models\Status\PipelineStatus',"
      59 => "'pipeline_id',"
      60 => "'id',"
      61 => "'status_id',"
      62 => "'id'"
      63 => ");
    

    Not sure what I broke in detail, but I just overjump the error with

    if(!isset($matches[1])) {
                            continue;
                        }
    

    Would be great if you could have a look on this. Thank you.

    opened by Nowi5 0
Releases(1.0.3)
Owner
Andy Abi Haidar
CTO / Managing Partner @ Yellow
Andy Abi Haidar
Library for counting the lines of code in PHP source code

sebastian/lines-of-code Library for counting the lines of code in PHP source code. Installation You can add this library as a local, per-project depen

Sebastian Bergmann 715 Jan 5, 2023
A full-scale PHP sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code

A full-scale PHP 7.4+ sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code. It also utilizes FunctionParser to di

Corveda 192 Dec 10, 2022
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

PHP-Projects hacktoberfest Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to cha

Firmansyah Helmi Kurniawan 43 Nov 28, 2022
PHP Static Analysis Tool - discover bugs in your code without running it!

PHPStan - PHP Static Analysis Tool PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even b

PHPStan 11.6k Dec 30, 2022
Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.

QOSSMIC GmbH 2.2k Dec 30, 2022
A PHP code-quality tool

GrumPHP Sick and tired of defending code quality over and over again? GrumPHP will do it for you! This composer plugin will register some git hooks in

PHPro 3.9k Jan 1, 2023
Code Climate CLI

Code Climate CLI Overview codeclimate is a command line interface for the Code Climate analysis platform. It allows you to run Code Climate engines on

Code Climate 2.4k Dec 26, 2022
Copy/Paste Detector (CPD) for PHP code.

PHP Copy/Paste Detector (PHPCPD) phpcpd is a Copy/Paste Detector (CPD) for PHP code. Installation This tool is distributed as a PHP Archive (PHAR): $

Sebastian Bergmann 2.2k Jan 1, 2023
Analyze PHP code with one command

PHPQA Analyze PHP code with one command. Requirements PHP >= 5.4.0 xsl extension for HTML reports Why? Every analyzer has different arguments and opti

edgedesign/phpqa 542 Dec 24, 2022
Static code analysis to find violations in a dependency graph

PhpDependencyAnalysis PhpDependencyAnalysis is an extendable static code analysis for object-oriented PHP-Projects to generate dependency graphs from

Marco Muths 546 Dec 7, 2022
Performs advanced static analysis on PHP code

PHP Analyzer Please report bugs or feature requests via our website support system ? in bottom right or by emailing [email protected]. Contri

Continuous Inspection 443 Sep 23, 2022
A static php code analysis tool using the Graph Theory

Mondrian Ok guyz, you have a master degree in Graph Theory, you follow Law of Demeter and you live on S.O.L.I.D principles ? Let's have some Fun ! (^ω

Florent Genette 391 Nov 30, 2022
Instant Upgrades and Instant Refactoring of any PHP 5.3+ code

Rector - Speedup Your PHP Development Rector helps you with 2 areas - major code changes and in daily work. Do you have a legacy code base? Do you wan

RectorPHP 6.5k Jan 8, 2023
Provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths

sebastian/environment This component provides functionality that helps writing PHP code that has runtime-specific (PHP / HHVM) execution paths. Instal

Sebastian Bergmann 6.5k Jan 3, 2023
Search PHP source code for function & method calls, variables, and more from PHP.

Searching PHP source code made easy Search PHP source code for function & method calls, variable assignments, classes and more directly from PHP. Inst

Permafrost Software 22 Nov 24, 2022
The Stopwatch component provides a way to profile code.

Stopwatch Component The Stopwatch component provides a way to profile code.

Symfony 2.6k Dec 28, 2022
phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in PHP code

phpcs-security-audit v3 About phpcs-security-audit is a set of PHP_CodeSniffer rules that finds vulnerabilities and weaknesses related to security in

Floe design + technologies 655 Jan 3, 2023
A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code 24 Aug 27, 2022
PHP code scanner to use with gettext/gettext

PHP code scanner to use with gettext/gettext

Gettext 12 Nov 11, 2022