| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Webmozart\Assert\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * QuarterPilotMissionCollection class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author Laurent De Coninck <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class QuarterPilotMissionCollection implements IteratorAggregate | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @var array|QuarterMission[] | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     private $items; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->items = []; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * @param int $quarter | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @param int $pilotId | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @param string $pilotFirstname | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * @param string $pilotLastname | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * @param int $numberOfFlights | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @param int $numberOfKilometers | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function addMission( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $quarter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $pilotId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $pilotFirstname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $pilotLastname, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $numberOfFlights, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $numberOfKilometers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         Assert::integerish($pilotId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $pilotId = (int)$pilotId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (!isset($this->items[$pilotId])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $this->items[$pilotId] = new PilotMissions($pilotId, $pilotFirstname, $pilotLastname); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->items[$pilotId]->addQuarter($quarter, $numberOfFlights, $numberOfKilometers); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * @param int $pilotId | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * @param string $pilotFirstname | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @param string $pilotLastname | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function addPilot($pilotId, $pilotFirstname, $pilotLastname) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         Assert::integerish($pilotId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $pilotId = (int)$pilotId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         if (isset($this->items[$pilotId])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->items[$pilotId] = new PilotMissions($pilotId, $pilotFirstname, $pilotLastname); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      * @return ArrayIterator | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     public function getIterator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return new ArrayIterator($this->items); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * @return boolean | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     public function hasMission() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         return !empty($this->items); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  | } |