private function getPlayer($wsId, Team $team = null) { if (array_key_exists($wsId, $this->players)) { $player = $this->players[$wsId]; } else { $player = $this->em->getRepository('AppBundle:Player')->findOneByWsId($wsId); } if ($player == null) { try { $data = $this->whoscored->getPlayerData($wsId); } catch (\Exception $e) { throw $e; } $player = new Player(); $player->setFirstName($data->firstName); $player->setLastName($data->lastName); $player->setKnownName($data->knownName); $player->setAge($data->age); $player->setWsId($data->wsId); } if ($team !== null && $player->getTeam() !== $team) { $ret = $team; try { $teamId = $this->whoscored->getActiveTeam($wsId); $ret = $this->getTeam($teamId); $player->setTeam($ret); } catch (\Exception $e) { } finally { $player->setTeam($ret); } } $this->players[$wsId] = $player; $this->em->persist($player); return $player; }