| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Werkspot\KvkApi\Client\Factory\Profile; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DateTime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Werkspot\KvkApi\Api\Profile\Company; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Werkspot\KvkApi\Client\Factory\AbstractFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Werkspot\KvkApi\Client\Factory\Profile\Company\AddressFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Werkspot\KvkApi\Client\Factory\Profile\Company\BusinessActivityFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Werkspot\KvkApi\Client\Factory\Profile\Company\TradeNamesFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | final class CompanyFactory extends AbstractFactory implements CompanyFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @var AddressFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private $addressFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var BusinessActivityFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private $businessActivityFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var TradeNamesFactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $tradeNamesFactory; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 | 19 |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         TradeNamesFactoryInterface $tradeNamesFactory, | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         BusinessActivityFactoryInterface $businessActivityFactory, | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         AddressFactoryInterface $addressFactory | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 19 |  |         $this->tradeNamesFactory = $tradeNamesFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 19 |  |         $this->businessActivityFactory = $businessActivityFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 | 19 |  |         $this->addressFactory = $addressFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 19 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 17 |  |     public function fromArray(array $data): Company | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 17 |  |         return new Company( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 17 |  |             $this->extractIntegerOrNull('kvkNumber', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 17 |  |             $this->extractStringOrNull('branchNumber', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 17 |  |             $this->extractIntegerOrNull('rsin', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 17 |  |             $this->tradeNamesFactory->fromArray($data['tradeNames']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 17 |  |             $this->extractStringOrNull('legalForm', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 17 |  |             $this->extractBusinessActivities($data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 17 |  |             $this->extractBoolean('hasEntryInBusinessRegister', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 17 |  |             $this->extractBoolean('hasCommercialActivities', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 17 |  |             $this->extractBoolean('hasNonMailingIndication', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 17 |  |             $this->extractBoolean('isLegalPerson', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 17 |  |             $this->extractBoolean('isBranch', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 17 |  |             $this->extractBoolean('isMainBranch', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 17 |  |             $this->extractIntegerOrNull('employees', $data), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 17 |  |             new DateTime($data['foundationDate']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 17 |  |             new DateTime($data['registrationDate']), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 17 |  |             $this->extractAddresses($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 17 |  |     private function extractBusinessActivities($data): ?array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 17 |  |         if (array_key_exists('businessActivities', $data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 15 |  |             return $this->businessActivityFactory->fromArray($data['businessActivities']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 2 |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 17 |  |     private function extractAddresses($data): ?array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 17 |  |         if (array_key_exists('addresses', $data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 16 |  |             return $this->addressFactory->fromArray($data['addresses']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  |