| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * PHP version 7.1 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This source file is subject to the license that is bundled with this package in the file LICENSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace PhUml\Graphviz; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PhUml\Code\ClassDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PhUml\Code\InterfaceDefinition; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class Digraph implements HasDotRepresentation | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** @var HasDotRepresentation[] */ | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     private $dotElements; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     /** @var InterfaceGraphElements */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     private $interfaceElements; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** @var ClassGraphElements */ | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     private $classElements; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         InterfaceGraphElements $interfaceElements, | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         ClassGraphElements $classElements | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->dotElements = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $this->interfaceElements = $interfaceElements; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->classElements = $classElements; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function fromCodeStructure(array $structure): void | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         foreach ($structure as $definition) { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             if ($definition instanceof ClassDefinition) { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |                 $this->classElementsFrom($definition, $structure); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             } else if ($definition instanceof InterfaceDefinition) { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |                 $this->interfaceElementsFrom($definition); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     private function classElementsFrom(ClassDefinition $class, array $structure): void | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $this->dotElements = array_merge($this->dotElements, $this->classElements->extractFrom($class, $structure)); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     private function interfaceElementsFrom(InterfaceDefinition $interface): void | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->dotElements = array_merge($this->dotElements, $this->interfaceElements->extractFrom($interface)); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function toDotLanguage(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return "digraph \"{$this->graphId()}\" { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | splines = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | overlap = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | mindist = 0.6; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  | {$this->elementsToDotLanguage()}}"; | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     private function elementsToDotLanguage(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $dotFormat = array_map(function (HasDotRepresentation $element) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             return $element->toDotLanguage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         }, $this->dotElements); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  |         return implode('', $dotFormat); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 72 |  |  |     private function graphId(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |         return sha1(mt_rand()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                                                                
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  | 
            
                        
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.