| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Newage\Annotations\Mapper\Annotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Newage\Annotations\Entity\Annotation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Zend\EventManager\EventInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Zend\EventManager\EventManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class PropertyAnnotationListener | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package SimpleOrm\Mapper\Annotation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class PropertyAnnotationListener extends AbstractAnnotationListener | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function attach(EventManagerInterface $events) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->listeners[] = $events->attach('configureProperty', [$this, 'handleIdAnnotation']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->listeners[] = $events->attach('configureProperty', [$this, 'handleColumnAnnotation']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->listeners[] = $events->attach('configureProperty', [$this, 'handleOneToOneAnnotation']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $this->listeners[] = $events->attach('configureProperty', [$this, 'handleOneToManyAnnotation']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->listeners[] = $events->attach('configureProperty', [$this, 'handleManyToManyAnnotation']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 24 |  | View Code Duplication |     public function handleIdAnnotation(EventInterface $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $annotation = $event->getParam('annotation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         if (!$annotation instanceof Annotation\Id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $spec = $event->getParam('spec'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $spec['autoincrement'] = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 35 |  | View Code Duplication |     public function handleColumnAnnotation(EventInterface $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $annotation = $event->getParam('annotation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         if (!$annotation instanceof Annotation\Column) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $spec = $event->getParam('spec'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $spec['column'] = $annotation->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 46 |  | View Code Duplication |     public function handleOneToOneAnnotation(EventInterface $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $annotation = $event->getParam('annotation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (!$annotation instanceof Annotation\OneToOne) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $spec = $event->getParam('spec'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $spec['oneToOne'] = $annotation->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 57 |  | View Code Duplication |     public function handleOneToManyAnnotation(EventInterface $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $annotation = $event->getParam('annotation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         if (!$annotation instanceof Annotation\OneToMany) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $spec = $event->getParam('spec'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $spec['oneToMany'] = $annotation->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 68 |  | View Code Duplication |     public function handleManyToManyAnnotation(EventInterface $event) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         $annotation = $event->getParam('annotation'); | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         if (!$annotation instanceof Annotation\ManyToMany) { | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |             return; | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |         $spec = $event->getParam('spec'); | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         $spec['manyToMany'] = $annotation->getName(); | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.