| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Ogone\DirectLink; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class MaintenanceOperation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     const OPERATION_AUTHORISATION_RENEW = 'REN'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     const OPERATION_AUTHORISATION_DELETE = 'DEL'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     const OPERATION_AUTHORISATION_DELETE_AND_CLOSE = 'DES'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     const OPERATION_CAPTURE_PARTIAL = 'SAL'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     const OPERATION_CAPTURE_LAST_OR_FULL = 'SAS'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     const OPERATION_REFUND_PARTIAL = 'RFD'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     const OPERATION_REFUND_LAST_OR_FULL = 'RFS'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected $operation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 17 | 8 | View Code Duplication |     public function __construct($operation) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 8 |  |         if(!in_array($operation, self::getAllAvailableOperations())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 2 |  |             throw new \InvalidArgumentException('Unknown Operation: ' . $operation); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 6 |  |         $this->operation = $operation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 6 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 1 |  |     public function equals(MaintenanceOperation $other) | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 1 |  |         return $this->operation === $other->operation; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 5 |  |     public function __toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 5 |  |         return (string) $this->operation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 8 |  |     private function getAllAvailableOperations() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 8 |  |             self::OPERATION_AUTHORISATION_RENEW, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 8 |  |             self::OPERATION_AUTHORISATION_DELETE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 8 |  |             self::OPERATION_AUTHORISATION_DELETE_AND_CLOSE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 8 |  |             self::OPERATION_CAPTURE_PARTIAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 8 |  |             self::OPERATION_CAPTURE_LAST_OR_FULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 8 |  |             self::OPERATION_REFUND_PARTIAL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 8 |  |             self::OPERATION_REFUND_LAST_OR_FULL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 8 |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 48 |  |  | }  | 
            
                        
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.