| 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\Members; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PhpParser\Node\Stmt\Property; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PhUml\Code\Attributes\Attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PhUml\Code\Attributes\AttributeDocBlock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PhUml\Code\Attributes\StaticAttribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PhUml\Code\Variables\TypeDeclaration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PhUml\Parser\Code\Builders\Filters\PrivateVisibilityFilter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PhUml\Parser\Code\Builders\Filters\ProtectedVisibilityFilter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * It builds an array of `Attributes` for a `ClassDefinition` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * It can run one or more `VisibilityFilter`s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @see PrivateVisibilityFilter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @see ProtectedVisibilityFilter | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | class AttributesBuilder extends MembersBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * @param \PhpParser\Node[] $definitionAttributes | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * @return Attribute[] | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     public function build(array $definitionAttributes): array | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 93 |  |         $attributes = array_filter($definitionAttributes, function ($attribute) { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 | 84 |  |             return $attribute instanceof Property; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 93 |  |         }); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 93 |  |         return array_map(function (Property $attribute) { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 75 |  |             $name = "\${$attribute->props[0]->name}"; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 75 |  |             $modifier = $this->resolveVisibility($attribute); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 | 75 |  |             $comment = $attribute->getDocComment(); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 | 75 |  |             if ($attribute->isStatic()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 | 48 |  |                 return StaticAttribute::$modifier($name, $this->extractTypeFrom($comment)); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 | 75 |  |             return Attribute::$modifier($name, $this->extractTypeFrom($comment)); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 | 93 |  |         }, $this->runFilters($attributes)); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 75 |  |     private function extractTypeFrom(?string $comment): TypeDeclaration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 75 |  |         if ($comment === null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 72 |  |             return TypeDeclaration::absent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 55 | 60 |  |         return AttributeDocBlock::from($comment)->extractType(); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  |