| 1 |  |  | <?php declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Suilven\CovidAPIClient\Model; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  | class Results | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  |     /** @var array<\Suilven\CovidAPIClient\Model\SingleEntry> */ | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  |     private $records = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |     /** @var int */ | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     private $pageSize; | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     /** @var int */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     private $numberOfResults; | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /** @var string|null */ | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     private $prevLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     /** @var string|null */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     private $nextLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     /** @var string */ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     private $firstLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     /** @var string */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     private $lastLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     /** @var string */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     private $currentLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * Results constructor. | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     public function __construct(string $json) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         $decoded = \json_decode($json, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         // deal with the entries retrieved first | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         foreach ($decoded['data'] as $entryOrig) { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |             $normalizedEntry = new SingleEntry(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             $normalizedEntry->setDate($entryOrig['date']); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             $normalizedEntry->setAreaName($entryOrig['areaName']); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             $normalizedEntry->setAreaCode($entryOrig['areaCode']); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             $normalizedEntry->setNewCasesByPublishDate($entryOrig['newCasesByPublishDate']); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             $normalizedEntry->setNewDeaths28DaysByDeathDate($entryOrig['newDeaths28DaysByDeathDate']); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             $normalizedEntry->setCumCasesByPublishDate($entryOrig['cumCasesByPublishDate']); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             $normalizedEntry->setCumDeaths28DaysByDeathDate($entryOrig['cumDeaths28DaysByDeathDate']); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |             $this->records[] = $normalizedEntry; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->pageSize = $decoded['maxPageLimit']; | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $this->numberOfResults = $decoded['length']; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->nextLink = $decoded['pagination']['next']; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $this->prevLink = $decoded['pagination']['previous']; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $this->firstLink = $decoded['pagination']['first']; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $this->lastLink = $decoded['pagination']['last']; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         $this->currentLink = $decoded['pagination']['current']; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function getCurrentLink(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  |         return $this->currentLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     public function getPageSize(): int | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         return $this->pageSize; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     public function getNumberOfResults(): int | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         return $this->numberOfResults; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     public function getPrevLink(): ?string | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         return $this->prevLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     public function getNextLink(): ?string | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         return $this->nextLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     public function getFirstLink(): string | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |         return $this->firstLink; | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function getLastLink(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  |         return $this->lastLink; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     /** @return array<\Suilven\CovidAPIClient\Model\SingleEntry> */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     public function getRecords(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  |         return $this->records; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 108 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 109 |  |  |  |