| 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\Parser\Code\Builders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PhpParser\Node\Name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PhpParser\Node\Stmt\Interface_; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PhUml\Code\InterfaceDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PhUml\Code\Name as InterfaceDefinitionName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PhUml\Parser\Code\Builders\Members\ConstantsBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PhUml\Parser\Code\Builders\Members\MethodsBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * It builds an `InterfaceDefinition` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @see ConstantsBuilder for more details about the constants creation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @see MethodsBuilder for more details about the methods creation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class InterfaceDefinitionBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var MethodsBuilder */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $methodsBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** @var ConstantsBuilder */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $constantsBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 129 |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ConstantsBuilder $constantsBuilder = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         MethodsBuilder $methodsBuilder = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 129 |  |         $this->constantsBuilder = $constantsBuilder ?? new ConstantsBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 129 |  |         $this->methodsBuilder = $methodsBuilder ?? new MethodsBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 129 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 48 |  |     public function build(Interface_ $interface): InterfaceDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 48 |  |         return new InterfaceDefinition( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 48 |  |             InterfaceDefinitionName::from($interface->name), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 48 |  |             $this->constantsBuilder->build($interface->stmts), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 48 |  |             $this->methodsBuilder->build($interface->getMethods()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 48 |  |             $this->buildParents($interface) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |     /** @return InterfaceDefinitionName[] */ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     protected function buildParents(Interface_ $interface): array | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 48 |  |         return array_map(function (Name $name) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 6 |  |             return InterfaceDefinitionName::from($name->getLast()); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 48 |  |         }, $interface->extends); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  |