| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Betfair\Model\PlaceOrders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Betfair\Exception\ModelException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Betfair\Model\Side; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class PlaceInstruction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function __construct($orderType, $selectionId, Side $side) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $this->setValidOrderType($orderType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $this->selectionId = $selectionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $this->setValidSide($side); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** @var  OrderType */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $orderType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** @var  int */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private $selectionId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var  float */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $handicap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** @var  LimitOrder */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $limitOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private $limitOnCloseOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private $marketOnCloseOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** @var  Side */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private $side; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function setValidOrderType($orderType) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->validateOrderTypeOrThrowException($orderType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->orderType = $orderType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function setValidSide($side) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->validateSideOrThrowException($side); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->side = $side; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication |     private function validateOrderTypeOrThrowException($orderType) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         if(!in_array($orderType, OrderType::toArray())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             throw new ModelException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     "Invalid Order Type %s. Valid ones are %s", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                     $orderType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     implode(",", OrderType::toArray()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 63 |  | View Code Duplication |     private function validateSideOrThrowException($side) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         if(!in_array($side, Side::toArray())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             throw new ModelException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                     "Invalid Side %s. Valid ones are %s", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     $side, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                     implode(",", Side::toArray()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param float $handicap | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function setHandicap($handicap) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->handicap = $handicap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param mixed $limitOnCloseOrder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public function setLimitOnCloseOrder($limitOnCloseOrder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->limitOnCloseOrder = $limitOnCloseOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param mixed $limitOrder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     public function setLimitOrder($limitOrder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->limitOrder = $limitOrder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @param mixed $marketOnCloseOrder | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |     public function setMarketOnCloseOrder($marketOnCloseOrder) | 
            
                                                        
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |         $this->marketOnCloseOrder = $marketOnCloseOrder; | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 107 |  |  | }  | 
            
                        
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.