MontealegreLuis / phuml

phUML is a UML diagram generator. It takes arbitrary object oriented PHP code and creates fully blown class diagrams of it.
BSD 3-Clause "New" or "Revised" License
100 stars 19 forks source link

Fix lost FQN in TypeDeclaration::references() and UseStatments::fullyQualifiedNameFor() #19

Closed Amegatron closed 2 years ago

Amegatron commented 2 years ago

This PR addresses https://github.com/MontealegreLuis/phuml/issues/18

MontealegreLuis commented 2 years ago

Thank you @Amegatron!!

Could you please pin PHP Parser dependency in composer.json (line 21) to 4.11.0. It looks like 4.13 uses incompatible type declarations

"nikic/php-parser": "4.11.0"
Amegatron commented 2 years ago

Done 👍 Also, found some other bugs in parsing and will make PRs once I figure them out.

Amegatron commented 2 years ago

Damn, forgot to start new branch for other issues. Should I recreate the PR, or it is OK to merge them all-together? There is still one more bug I wanna fix today concerning that same "references": compound types like array<type1,type2> are not understood well by parser and they go as separate "references".

MontealegreLuis commented 2 years ago

I'm okay with fixing #18 and #20 in this PR. Could you please also open an issue for array<type1, type2>? I'm not sure how standard is that notation and how it should look in the diagram.

Could you please elaborate a little bit more in a new issue?

Also not sure if Git hooks are working. I thought they would validate commit format (I've been following the conventional commits specification)

It's not a big deal, but was wondering if I need to fix the Git hooks set up.

MontealegreLuis commented 2 years ago

Thank you @Amegatron!

Amegatron commented 2 years ago

You're welcome!

As for array<...> notation, it is pretty common in PhpDoc if you want to specify the contents of an array. For example, array<int> means that this is array of only ints. array<string,MyClass> essentially means a hash-map: keys are strings, and elements themselves are objects of MyClass. For now I'm not yet sure how exactly does it look in "out-of-the-box" diagrams, but since I use this library mostly as an tool to generate my own formats of diagrams, I get those array<...> when I try to get TypeDeclaration::rerefences(). I'll try to check it out today.

Also, this notation is used not only in arrays, but for any kinds of "lists". For example, if you're using any Collection class (implementing ArrayAccess or related), you can also specifcy the types for keys and values in the same format, like Collection<MyClass>. Concerning this last scenario, I also sometimes get strange references, though not yet sure how to reproduce it: sometimes I get such references as Collection<, or MyType> - with those junky brackets added to the type itself. Still need to investigate this issue more.

P.S. it is also worth noting, that this notation allows lots of nested levels, for example array<int,array<string,MyClass>>, etc, which means literally this: array with number-keys, elements of which are arrays with string-keys (hash-map) and values are objects of MyClass :)

Amegatron commented 2 years ago

As for the git hooks, I believe all the tests have passed automatically, but it told me approval was still needed for new contributors, that's why it didn't merge itself. If that was the question :)

MontealegreLuis commented 2 years ago

You're welcome!

As for array<...> notation, it is pretty common in PhpDoc if you want to specify the contents of an array. For example, array<int> means that this is array of only ints. array<string,MyClass> essentially means a hash-map: keys are strings, and elements themselves are objects of MyClass. For now I'm not yet sure how exactly does it look in "out-of-the-box" diagrams, but since I use this library mostly as an tool to generate my own formats of diagrams, I get those array<...> when I try to get TypeDeclaration::rerefences(). I'll try to check it out today.

Also, this notation is used not only in arrays, but for any kinds of "lists". For example, if you're using any Collection class (implementing ArrayAccess or related), you can also specifcy the types for keys and values in the same format, like Collection<MyClass>. Concerning this last scenario, I also sometimes get strange references, though not yet sure how to reproduce it: sometimes I get such references as Collection<, or MyType> - with those junky brackets added to the type itself. Still need to investigate this issue more.

P.S. it is also worth noting, that this notation allows lots of nested levels, for example array<int,array<string,MyClass>>, etc, which means literally this: array with number-keys, elements of which are arrays with string-keys (hash-map) and values are objects of MyClass :)

I see. Thank you for the explanation. I think this would be a feature request to support "generics" in doc blocks.

MontealegreLuis commented 2 years ago

As for the git hooks, I believe all the tests have passed automatically, but it told me approval was still needed for new contributors, that's why it didn't merge itself. If that was the question :)

When you committed a few tasks should have been run automatically, and if you ran your commit from a terminal, you should have seen an output similar to the one below.

GrumPHP detected a pre-commit command.
GrumPHP is sniffing your code!
Running tasks with priority 0!
==============================
Running task 1/6: composer... 
Running task 2/6: composer_normalize... 
Running task 3/6: phpstan... 
Running task 4/6: phpunit... 
Running task 5/6: phpcsfixer2... 
Running task 6/6: phpcsfixer2_test... 
Running task 1/6: composer... ✔
Running task 2/6: composer_normalize... ✔
Running task 3/6: phpstan... 
Running task 4/6: phpunit... 
Running task 5/6: phpcsfixer2... 
Running task 6/6: phpcsfixer2_test... 
GrumPHP detected a commit-msg command.
GrumPHP is sniffing your code!
Running tasks with priority 0!
==============================
Running task 1/1: git_commit_message... 
Running task 1/1: git_commit_message... ✔
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌           
         ▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
  ▄▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌        
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄████████▀▀▀▀▀                 ██████████   
     ███████▀                         ██████▀
      ▐████      ██▌          ██       ████▌      
        ▐█▌                            ███        
         █▌           ▄▄ ▄▄           ▐███        
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███         
         ██▄ ▐███████████████████████████
        █▀█████████▌▀▀▀▀▀▀▀▀▀██████████▌▐         
          ███████████▄▄▄▄▄▄▄███████████▌          
         ▐█████████████████████████████           
          █████████████████████████████           
           ██ █████████████████████▐██▀           
            ▀ ▐███████████████████▌ ▐▀            
                ████▀████████▀▐███                
                 ▀█▌  ▐█████  ▐█▌                 
                        ██▀   ▐▀                  
       _    _ _                         _ _
      / \  | | |   __ _  ___   ___   __| | |
     / _ \ | | |  / _` |/ _ \ / _ \ / _` | |
    / ___ \| | | | (_| | (_) | (_) | (_| |_|
   /_/   \_\_|_|  \__, |\___/ \___/ \__,_(_)
                  |___/

I don't know if that's how it worked for you.