/** * Creates a player object with the given data * @param array $data an associative array to fill up the members of the * player class * @return Player a player object with the data given as it's members */ public static function create(array $data) : Player { $player = new Player(); parent::fill($data, $player); if (is_array($player->clan)) { $player->clan = Clan::create($player->clan); } if (is_array($player->league)) { $player->league = League::create($player->league); } return $player; }
/** * Based on a Location, retrieve the local rankings * @param int $id the unique identifier of the location * @param string|RankingId $rank the kind of ranking you want to retrieve. * Based on Clans and based on players is supported at the moment. * @return The clans/player who are located at the location id */ private function _locationsByIdAndRank(int $id, $rank) { $curlClient = curl_init(self::BASE_URL . self::LOCATIONS_URL . '/' . $id . '/rankings/' . $rank); curl_setopt($curlClient, CURLOPT_HTTPHEADER, $this->_curlHeader); curl_setopt($curlClient, CURLOPT_RETURNTRANSFER, true); $results = json_decode(curl_exec($curlClient), true); $items = []; foreach ($results['items'] as $result) { if ($rank === RankingId::CLANS) { $items[] = Clan::create($result); } else { $items[] = Player::create($result); } } return $items; }