| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace PtrTn\Battlerite\Dto\Match; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DateTime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PtrTn\Battlerite\Assert\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @SuppressWarnings(PHPMD.CouplingBetweenObjects) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class DetailedMatch | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var DateTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public $createdAt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public $duration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public $gameMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public $patchVersion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public $shardId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public $titleId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @var Map | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public $map; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @var Assets | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public $assets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var Spectators | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public $spectators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @var Rosters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public $rosters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @var Rounds | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public $rounds; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @var Participants | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public $participants; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @var Players | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public $players; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @SuppressWarnings(PHPMD.ExcessiveParameterList) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 4 |  |     private function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         string $type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         string $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         DateTime $createdAt, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         int $duration, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         string $gameMode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         string $patchVersion, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         string $shardId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         string $titleId, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         Map $map, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         Assets $assets, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         Spectators $spectators, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         Rosters $rosters, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         Rounds $rounds, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         Participants $participants, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         Players $players | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 4 |  |         $this->type = $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 4 |  |         $this->id = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 4 |  |         $this->createdAt = $createdAt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 4 |  |         $this->duration = $duration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 4 |  |         $this->gameMode = $gameMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 4 |  |         $this->patchVersion = $patchVersion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 4 |  |         $this->shardId = $shardId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 4 |  |         $this->titleId = $titleId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 4 |  |         $this->map = $map; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 4 |  |         $this->assets = $assets; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 4 |  |         $this->spectators = $spectators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 4 |  |         $this->rosters = $rosters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 4 |  |         $this->rounds = $rounds; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 4 |  |         $this->participants = $participants; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 4 |  |         $this->players = $players; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 4 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 | 4 |  |     public static function createFromArray(array $match): self | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 | 4 |  |         $matchData = $match['data']; | 
            
                                                                        
                            
            
                                    
            
            
                | 128 | 4 |  |         Assert::string($matchData['type']); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 | 4 |  |         Assert::string($matchData['id']); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 | 4 |  |         Assert::date($matchData['attributes']['createdAt'], DateTime::ISO8601); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 | 4 |  |         Assert::integer($matchData['attributes']['duration']); | 
            
                                                                        
                            
            
                                    
            
            
                | 132 | 4 |  |         Assert::string($matchData['attributes']['gameMode']); | 
            
                                                                        
                            
            
                                    
            
            
                | 133 | 4 |  |         Assert::string($matchData['attributes']['patchVersion']); | 
            
                                                                        
                            
            
                                    
            
            
                | 134 | 4 |  |         Assert::string($matchData['attributes']['shardId']); | 
            
                                                                        
                            
            
                                    
            
            
                | 135 | 4 |  |         Assert::isArray($matchData['attributes']['stats']); | 
            
                                                                        
                            
            
                                    
            
            
                | 136 | 4 |  |         Assert::string($matchData['attributes']['titleId']); | 
            
                                                                        
                            
            
                                    
            
            
                | 137 | 4 |  |         Assert::isArray($matchData['relationships']['assets']['data']); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 | 4 |  |         Assert::isArray($matchData['relationships']['rosters']['data']); | 
            
                                                                        
                            
            
                                    
            
            
                | 139 | 4 |  |         Assert::isArray($matchData['relationships']['rounds']['data']); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 | 4 |  |         Assert::isArray($matchData['relationships']['spectators']['data']); | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 142 | 4 |  |         $matchIncludes = $match['included']; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 144 | 4 |  |         $participants = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 145 | 4 |  |         $rosters = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 | 4 |  |         $rounds = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 | 4 |  |         $players = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 148 | 4 |  |         foreach ($matchIncludes as $include) { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 | 4 |  |             Assert::string($include['type']); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 | 4 |  |             switch ($include['type']) { | 
            
                                                                        
                            
            
                                    
            
            
                | 151 | 4 |  |                 case 'participant': | 
            
                                                                        
                            
            
                                    
            
            
                | 152 | 4 |  |                     $participants[] = Participant::createFromArray($include); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 | 4 |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 154 | 4 |  |                 case 'roster': | 
            
                                                                        
                            
            
                                    
            
            
                | 155 | 4 |  |                     $rosters[] = Roster::createFromArray($include); | 
            
                                                                        
                            
            
                                    
            
            
                | 156 | 4 |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 157 | 4 |  |                 case 'round': | 
            
                                                                        
                            
            
                                    
            
            
                | 158 | 4 |  |                     $rounds[] = Round::createFromArray($include); | 
            
                                                                        
                            
            
                                    
            
            
                | 159 | 4 |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 160 | 4 |  |                 case 'player': | 
            
                                                                        
                            
            
                                    
            
            
                | 161 | 4 |  |                     $players[] = Player::createFromArray($include); | 
            
                                                                        
                            
            
                                    
            
            
                | 162 | 4 |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 166 | 4 |  |         return new self( | 
            
                                                                        
                            
            
                                    
            
            
                | 167 | 4 |  |             $matchData['type'], | 
            
                                                                        
                            
            
                                    
            
            
                | 168 | 4 |  |             $matchData['id'], | 
            
                                                                        
                            
            
                                    
            
            
                | 169 | 4 |  |             DateTime::createFromFormat(DateTime::ISO8601, $matchData['attributes']['createdAt']), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 170 | 4 |  |             $matchData['attributes']['duration'], | 
            
                                                                        
                            
            
                                    
            
            
                | 171 | 4 |  |             $matchData['attributes']['gameMode'], | 
            
                                                                        
                            
            
                                    
            
            
                | 172 | 4 |  |             $matchData['attributes']['patchVersion'], | 
            
                                                                        
                            
            
                                    
            
            
                | 173 | 4 |  |             $matchData['attributes']['shardId'], | 
            
                                                                        
                            
            
                                    
            
            
                | 174 | 4 |  |             $matchData['attributes']['titleId'], | 
            
                                                                        
                            
            
                                    
            
            
                | 175 | 4 |  |             Map::createFromArray($matchData['attributes']['stats']), | 
            
                                                                        
                            
            
                                    
            
            
                | 176 | 4 |  |             Assets::createFromArray($matchData['relationships']['assets']['data']), | 
            
                                                                        
                            
            
                                    
            
            
                | 177 | 4 |  |             Spectators::createFromArray($matchData['relationships']['spectators']['data']), | 
            
                                                                        
                            
            
                                    
            
            
                | 178 | 4 |  |             new Rosters($rosters), | 
            
                                                                        
                            
            
                                    
            
            
                | 179 | 4 |  |             new Rounds($rounds), | 
            
                                                                        
                            
            
                                    
            
            
                | 180 | 4 |  |             new Participants($participants), | 
            
                                                                        
                            
            
                                    
            
            
                | 181 | 4 |  |             new Players($players) | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 1 |  |     public function hasPlayerWon(string $playerId): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 | 1 |  |         $winningParticipants = $this->rosters->getWinningParticipants(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 | 1 |  |         foreach ($this->participants as $participant) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 1 |  |             foreach ($winningParticipants as $winningParticipant) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 | 1 |  |                 if ($participant->id === $winningParticipant->id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 1 |  |                     if ($participant->userID === $playerId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 1 |  |                         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 | 1 |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 199 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 200 |  |  |  |