| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ups\Entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DOMDocument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use DOMElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Ups\NodeInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ServiceOffering implements NodeInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     const SO_DIRECT_TO_RETAIL = '001'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     const SO_NOT_IN_ONE_ADL = '002'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     const SO_CLICK_AND_COLLECT = '003'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     const SO_RETAIL_TO_RETAIL = '004'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     const SO_PICKUP = '005'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     const SO_DROP_OFF = '006'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     const SO_PUDO = '007'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     const SO_EARLY_PICKUP_DELIVERY_TIME = '008'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     const SO_ACCEPT_PREPAID_DROP_OFFS = '009'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     const SO_DCO_DCR_INTERCEPT_ACCEPTED = '010'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     const SO_ACCEPTS_PAYMENTS = '011'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     const SO_PAY_AT_STORE = '012'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     const SO_ACCEPTS_RESTRICTED_ARTICLES = '013'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private static $serviceOfferingNames = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         '001' => 'Direct To Retail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         '002' => 'Not In One ADL', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         '003' => 'Click and Collect', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         '004' => 'Retail to Retail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         '005' => 'Pickup', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         '006' => 'Drop Off', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         '007' => 'PUDO', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         '008' => 'Early Pickup Delivery Time', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         '009' => 'Accept prepaid drop offs', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         '010' => 'DCO DCR intercept accepted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         '011' => 'Accepts Payments', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         '012' => 'Pay At Store', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         '013' => 'Accepts Restricted Articles', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param null|object $serviceOfferingCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |     public function __construct($serviceOfferingCode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |         $this->code = $serviceOfferingCode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public static function getServiceOfferings() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return self::$serviceOfferingNames; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param null|DOMDocument $document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return DOMElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |     public function toNode(DOMDocument $document = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |         if (null === $document) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $document = new DOMDocument(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |         $node = $document->createElement('ServiceOffering'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  |         $node->appendChild($document->createElement('Code', $this->getCode())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1 |  |         return $node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function getName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         return self::$serviceOfferingNames[$this->getCode()]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 94 | 1 |  |     public function getCode() | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 1 |  |         return $this->code; | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @param string $code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function setCode($code) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $this->code = $code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 110 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 111 |  |  |  | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.