| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace LauLamanApps\eCurring\Http\Resource; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DateTime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use LauLamanApps\eCurring\Resource\Customer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use LauLamanApps\eCurring\Resource\Subscription; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | final class UpdateParser implements UpdateParserInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     public function parse(Updatable $object): array | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |         if ($object instanceof Customer) { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |             return $this->getCustomerPatchData($object); | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         if ($object instanceof Subscription) { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |             return $this->getSubscriptionPatchData($object); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         } | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private function getCustomerPatchData(Customer $customer): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $data = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             'first_name' => $customer->getFirstName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'last_name' => $customer->getLastName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'email' => $customer->getEmail(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         if ($customer->getGender()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $data['gender'] = $customer->getGender(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if ($customer->getMiddleName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $data['middle_name'] = $customer->getMiddleName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if ($customer->getCompanyName()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $data['company_name'] = $customer->getCompanyName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         if ($customer->getVatNumber()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $data['vat_number'] = $customer->getVatNumber(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         if ($customer->getPostalcode()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $data['postalcode'] = $customer->getPostalcode(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         if ($customer->getHouseNumber()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $data['house_number'] = $customer->getHouseNumber(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         if ($customer->getHouseNumberAdd()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $data['house_number_add'] = $customer->getHouseNumberAdd(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         if ($customer->getStreet()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $data['street'] = $customer->getStreet(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         if ($customer->getCity()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $data['city'] = $customer->getCity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         if ($customer->getCountryCode()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $data['country_iso2'] = $customer->getCountryCode(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         if ($customer->getLanguage()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $data['language'] = $customer->getLanguage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         if ($customer->getTelephone()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $data['telephone '] = $customer->getTelephone(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  |         return $data; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     private function getSubscriptionPatchData(Subscription $subscription): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $data = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         if ($subscription->getMandate()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $data['mandate_accepted'] = $subscription->getMandate()->isAccepted(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             $data['mandate_accepted_date'] = $subscription->getMandate()->getAcceptedDate()->format(DateTime::ATOM); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if ($subscription->getStartDate()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $data['start_date '] = $subscription->getStartDate()->format(DateTime::ATOM); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         if ($subscription->getStatus()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             $data['status '] = $subscription->getStatus()->getValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         if ($subscription->getCancelDate()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $data['cancel_date '] = $subscription->getCancelDate()->format(DateTime::ATOM); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         if ($subscription->getResumeDate()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             $data['resume_date '] = $subscription->getResumeDate()->format(DateTime::ATOM); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         if ($subscription->isConfirmationSent() !== null) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             $data['confirmation_sent '] = $subscription->isConfirmationSent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if ($subscription->getSubscriptionWebhookUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $data['subscription_webhook_url '] = $subscription->getSubscriptionWebhookUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         if ($subscription->getTransactionWebhookUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $data['transaction_webhook_url '] = $subscription->getTransactionWebhookUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         if ($subscription->getSuccessRedirectUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $data['success_redirect_url '] = $subscription->getSuccessRedirectUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 124 |  |  |         return $data; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 126 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |  | 
            
                        
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: