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

Namespace is not taken into account when referencing classes from the same namespace #20

Closed Amegatron closed 2 years ago

Amegatron commented 2 years ago

If I have a namespaced class and somewhere inside of it (attributes, methods, whatever) I reference another class from that same namespace (so no import is needed), that referenced entity is resolved without FQN.

MontealegreLuis commented 2 years ago

Fixed in #19

Amegatron commented 2 years ago

It's actually another bug, not fixed in #19. #19 fixed the case, when type is FQN itself without import. But this issue is about referencing classes in the same namespace.

MontealegreLuis commented 2 years ago

The case you're mentioning looks good to me.

<?php
namespace My\Intersecting {
    class OneClass {}
    class AnotherClass {
        public function __construct(private OneClass|null $attribute)
        {
        }
    }
}

namespace Another {
    class ThirdClass {}
}

When running

bin/phuml phuml:dot -a src example.gv

It produces the file

digraph "c28524bef61d29a872d30f67acff34c4d8586c58" {
splines = true;
overlap = false;
mindist = 0.6;
"My\Intersecting\OneClass" [label=<<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#8892BF"><B><FONT COLOR="#FFFFFF" FACE="Helvetica" POINT-SIZE="12">OneClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2">&nbsp;</TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2">&nbsp;</TD></TR></TABLE>> shape=plaintext color="#2e3436"]
"My\Intersecting\OneClass" -> "My\Intersecting\AnotherClass" [dir=back arrowtail=none style=solid color="#2e3436"]
"My\Intersecting\AnotherClass" [label=<<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#8892BF"><B><FONT COLOR="#FFFFFF" FACE="Helvetica" POINT-SIZE="12">AnotherClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">-$attribute: OneClass|null</FONT><BR ALIGN="LEFT"/></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2"><FONT COLOR="#2e3436" FACE="Helvetica" POINT-SIZE="10">+__construct($attribute: OneClass|null)</FONT><BR ALIGN="LEFT"/></TD></TR></TABLE>> shape=plaintext color="#2e3436"]
"Another\ThirdClass" [label=<<TABLE CELLSPACING="0" BORDER="0" ALIGN="LEFT"><TR><TD BORDER="1" ALIGN="CENTER" BGCOLOR="#8892BF"><B><FONT COLOR="#FFFFFF" FACE="Helvetica" POINT-SIZE="12">ThirdClass</FONT></B></TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2">&nbsp;</TD></TR><TR><TD BORDER="1" ALIGN="LEFT" BGCOLOR="#f2f2f2">&nbsp;</TD></TR></TABLE>> shape=plaintext color="#2e3436"]
}

Which includes the right namespace for all classes in associations.

Do you have an example?

Amegatron commented 2 years ago

Hm, interesting. Right now I don't have exact example with a generated graph, cause I use just internals of the library to generate my own graphs. And I faced situations working with Codebase, when getting attributes' or method parameters' references, it returned truncated classnames in the described scenario. I'll try to give some concrete example later if I face it again.