From 340cc165cb1505324fceaa7cce90ec731c3a20a9 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Fri, 17 May 2024 19:36:24 +0200 Subject: [PATCH] Refactoring --- app/GameMissions/Abstracts/GameMission.php | 3 -- app/GameMissions/ColonisationMission.php | 1 - app/Http/Controllers/FleetController.php | 1 - .../Controllers/FleetEventsController.php | 29 ++++++++++--------- app/Http/Controllers/HighscoreController.php | 12 ++++---- app/Http/Controllers/MessagesController.php | 1 - app/Services/FleetMissionService.php | 23 +++++++-------- app/Services/HighscoreService.php | 11 +++---- app/Services/MessageService.php | 7 ----- app/Services/ObjectService.php | 27 ++++++----------- app/Services/PlanetListService.php | 25 ++++++---------- app/Services/PlanetService.php | 25 +++++++--------- app/Services/PlayerService.php | 16 +++++----- 13 files changed, 76 insertions(+), 105 deletions(-) diff --git a/app/GameMissions/Abstracts/GameMission.php b/app/GameMissions/Abstracts/GameMission.php index 987fd615..a9988c9b 100644 --- a/app/GameMissions/Abstracts/GameMission.php +++ b/app/GameMissions/Abstracts/GameMission.php @@ -119,8 +119,6 @@ public function startMissionSanityChecks(PlanetService $planet, Coordinate $targ /** * Deduct mission resources from the planet (when starting mission). - * - * @throws Exception */ public function deductMissionResources(PlanetService $planet, Resources $resources, UnitCollection $units): void { @@ -140,7 +138,6 @@ public function deductMissionResources(PlanetService $planet, Resources $resourc * @param Resources $resources * @param int $parent_id * @return void - * @throws Exception */ public function start(PlanetService $planet, Coordinate $targetCoordinate, UnitCollection $units, Resources $resources, int $parent_id = 0): void { diff --git a/app/GameMissions/ColonisationMission.php b/app/GameMissions/ColonisationMission.php index 8c593b95..20fe03cb 100644 --- a/app/GameMissions/ColonisationMission.php +++ b/app/GameMissions/ColonisationMission.php @@ -4,7 +4,6 @@ use Exception; use OGame\Factories\PlanetServiceFactory; -use OGame\Factories\PlayerServiceFactory; use OGame\GameMessages\ColonyEstablished; use OGame\GameMissions\Abstracts\GameMission; use OGame\GameMissions\Models\MissionPossibleStatus; diff --git a/app/Http/Controllers/FleetController.php b/app/Http/Controllers/FleetController.php index 72cac23c..4f5796b3 100644 --- a/app/Http/Controllers/FleetController.php +++ b/app/Http/Controllers/FleetController.php @@ -3,7 +3,6 @@ namespace OGame\Http\Controllers; use Exception; -use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\View\View; diff --git a/app/Http/Controllers/FleetEventsController.php b/app/Http/Controllers/FleetEventsController.php index a1495e6a..a6382ffb 100644 --- a/app/Http/Controllers/FleetEventsController.php +++ b/app/Http/Controllers/FleetEventsController.php @@ -2,11 +2,11 @@ namespace OGame\Http\Controllers; -use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Support\Carbon; use Illuminate\View\View; use OGame\Factories\PlanetServiceFactory; +use OGame\Models\FleetMission; use OGame\Models\Planet\Coordinate; use OGame\Models\Resources; use OGame\Services\FleetMissionService; @@ -17,16 +17,12 @@ class FleetEventsController extends OGameController /** * Returns fleet mission eventbox JSON. * + * @param FleetMissionService $fleetMissionService * @return JsonResponse - * @throws BindingResolutionException */ - public function fetchEventBox(): JsonResponse + public function fetchEventBox(FleetMissionService $fleetMissionService): JsonResponse { - /* - * {"components":[],"hostile":0,"neutral":0,"friendly":1,"eventType":"friendly","eventTime":3470,"eventText":"Transport","newAjaxToken":"6f0e9c23c750fcfc85de4833c79fec39"} - */ // Get all the fleet movements for the current user. - $fleetMissionService = app()->make(FleetMissionService::class); $friendlyMissionRows = $fleetMissionService->getActiveFleetMissionsForCurrentPlayer(); if ($friendlyMissionRows->isEmpty()) { @@ -36,12 +32,19 @@ public function fetchEventBox(): JsonResponse 'time_next_mission' => 0, ]; } else { + $firstMission = $friendlyMissionRows->first(); + + // Make sure $firstMission is an instance of FleetMission + if (!$firstMission instanceof FleetMission) { + throw new \UnexpectedValueException('Expected instance of FleetMission.'); + } + // TODO: make it a (view)model return type // TODO: refactor data retrieval and processing... duplicate with fetchEventList $friendlyMissions = [ 'mission_count' => $friendlyMissionRows->count(), - 'type_next_mission' => $fleetMissionService->missionTypeToLabel($friendlyMissionRows->first()->mission_type) . ($friendlyMissionRows->first()->parent_id ? ' (R)' : ''), - 'time_next_mission' => $friendlyMissionRows->first()->time_arrival - (int)Carbon::now()->timestamp, + 'type_next_mission' => $fleetMissionService->missionTypeToLabel($firstMission->mission_type) . ($firstMission->parent_id ? ' (R)' : ''), + 'time_next_mission' => $firstMission->time_arrival - (int)Carbon::now()->timestamp, ]; } @@ -60,20 +63,18 @@ public function fetchEventBox(): JsonResponse /** * Fetch the fleet event list HTML which contains all the fleet mission details. * + * @param FleetMissionService $fleetMissionService + * @param PlanetServiceFactory $planetServiceFactory * @return View - * @throws BindingResolutionException */ - public function fetchEventList(): View + public function fetchEventList(FleetMissionService $fleetMissionService, PlanetServiceFactory $planetServiceFactory): View { // Get all the fleet movements for the current user. - $fleetMissionService = app()->make(FleetMissionService::class); $friendlyMissionRows = $fleetMissionService->getActiveFleetMissionsForCurrentPlayer(); $fleet_events = []; foreach ($friendlyMissionRows as $row) { // Planet from service - $planetServiceFactory = app()->make(PlanetServiceFactory::class); - $eventRowViewModel = new FleetEventRowViewModel(); $eventRowViewModel->id = $row->id; $eventRowViewModel->mission_type = $row->mission_type; diff --git a/app/Http/Controllers/HighscoreController.php b/app/Http/Controllers/HighscoreController.php index dc759cb3..aed0536f 100644 --- a/app/Http/Controllers/HighscoreController.php +++ b/app/Http/Controllers/HighscoreController.php @@ -14,14 +14,15 @@ class HighscoreController extends OGameController * * @param Request $request * @param PlayerService $player + * @param HighscoreService $highscoreService * @return View */ - public function index(Request $request, PlayerService $player): View + public function index(Request $request, PlayerService $player, HighscoreService $highscoreService): View { $this->setBodyId('highscore'); return view('ingame.highscore.index')->with([ - 'initialContent' => $this->ajax($request, $player), + 'initialContent' => $this->ajax($request, $player, $highscoreService), ]); } @@ -30,9 +31,10 @@ public function index(Request $request, PlayerService $player): View * * @param Request $request * @param PlayerService $player + * @param HighscoreService $highscoreService * @return View */ - public function ajax(Request $request, PlayerService $player): View + public function ajax(Request $request, PlayerService $player, HighscoreService $highscoreService): View { // Check if we received category parameter, if so, use it to determine which highscore category to show. // 1 = players @@ -45,9 +47,9 @@ public function ajax(Request $request, PlayerService $player): View } if ($category == 1) { - return $this->ajaxPlayer($request, $player); + return $this->ajaxPlayer($request, $player, $highscoreService); } else { - return $this->ajaxAlliance($request, $player); + return $this->ajaxAlliance($request, $player, $highscoreService); } } diff --git a/app/Http/Controllers/MessagesController.php b/app/Http/Controllers/MessagesController.php index ddd0d571..8faa1601 100644 --- a/app/Http/Controllers/MessagesController.php +++ b/app/Http/Controllers/MessagesController.php @@ -2,7 +2,6 @@ namespace OGame\Http\Controllers; -use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\View\View; diff --git a/app/Services/FleetMissionService.php b/app/Services/FleetMissionService.php index 9756b7b4..7b3128e0 100644 --- a/app/Services/FleetMissionService.php +++ b/app/Services/FleetMissionService.php @@ -2,8 +2,6 @@ namespace OGame\Services; -use Exception; -use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Carbon; use OGame\Factories\GameMissionFactory; @@ -69,6 +67,11 @@ class FleetMissionService */ protected MessageService $messageService; + /** + * @var GameMissionFactory $gameMissionFactory + */ + protected GameMissionFactory $gameMissionFactory; + /** * The queue model where this class should get its data from. * @@ -79,11 +82,12 @@ class FleetMissionService /** * FleetMissionService constructor. */ - public function __construct(PlayerService $player, ObjectService $objects, MessageService $messageService) + public function __construct(PlayerService $player, ObjectService $objects, MessageService $messageService, GameMissionFactory $gameMissionFactory) { $this->player = $player; $this->objects = $objects; $this->messageService = $messageService; + $this->gameMissionFactory = $gameMissionFactory; $model_name = 'OGame\Models\FleetMission'; $this->model = new $model_name(); @@ -256,12 +260,10 @@ public function getFleetMissionById(int $id, bool $only_active = true): FleetMis * @param Resources $resources * @param int $parent_id * @return void - * @throws Exception */ public function createNewFromPlanet(PlanetService $planet, Coordinate $targetCoordinate, int $missionType, UnitCollection $units, Resources $resources, int $parent_id = 0): void { - $missionFactory = app()->make(GameMissionFactory::class); - $missionObject = $missionFactory->getMissionById($missionType, [ + $missionObject = $this->gameMissionFactory->getMissionById($missionType, [ 'fleetMissionService' => $this, 'messageService' => $this->messageService, ]); @@ -273,8 +275,6 @@ public function createNewFromPlanet(PlanetService $planet, Coordinate $targetCoo * * @param FleetMission $mission * @return void - * @throws BindingResolutionException - * @throws Exception */ public function updateMission(FleetMission $mission): void { @@ -283,8 +283,7 @@ public function updateMission(FleetMission $mission): void return; } - $missionFactory = app()->make(GameMissionFactory::class); - $missionObject = $missionFactory->getMissionById($mission->mission_type, [ + $missionObject = $this->gameMissionFactory->getMissionById($mission->mission_type, [ 'fleetMissionService' => $this, 'messageService' => $this->messageService, ]); @@ -296,7 +295,6 @@ public function updateMission(FleetMission $mission): void * * @param FleetMission $mission * @return void - * @throws BindingResolutionException */ public function cancelMission(FleetMission $mission): void { @@ -305,8 +303,7 @@ public function cancelMission(FleetMission $mission): void return; } - $missionFactory = app()->make(GameMissionFactory::class); - $missionObject = $missionFactory->getMissionById($mission->mission_type, [ + $missionObject = $this->gameMissionFactory->getMissionById($mission->mission_type, [ 'fleetMissionService' => $this, 'messageService' => $this->messageService, ]); diff --git a/app/Services/HighscoreService.php b/app/Services/HighscoreService.php index e2b63c7a..a15f910e 100644 --- a/app/Services/HighscoreService.php +++ b/app/Services/HighscoreService.php @@ -3,8 +3,8 @@ namespace OGame\Services; use Exception; -use Illuminate\Contracts\Container\BindingResolutionException; use OGame\Facades\AppUtil; +use OGame\Factories\PlayerServiceFactory; use OGame\Models\User; /** @@ -22,11 +22,14 @@ class HighscoreService */ protected int $highscoreType; + protected PlayerServiceFactory $playerServiceFactory; + /** * Highscore constructor. */ - public function __construct() + public function __construct(PlayerServiceFactory $playerServiceFactory) { + $this->playerServiceFactory = $playerServiceFactory; } /** @@ -122,7 +125,6 @@ public function getPlayerScoreEconomy(PlayerService $player): int * @param int $offset_start * @param int $return_amount * @return array> - * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function getHighscorePlayers(int $offset_start = 0, int $return_amount = 100): array { @@ -138,7 +140,7 @@ public function getHighscorePlayers(int $offset_start = 0, int $return_amount = // TODO: we get the player score per player now, but we should get it from a cached highscore table // to improve performance. Currently it works but is slow for large amounts of players. // Load player object with all planets. - $playerService = app()->make(PlayerService::class, ['player_id' => $player->id]); + $playerService = $this->playerServiceFactory->make($player->id); $score = 0; switch ($this->highscoreType) { case 1: @@ -193,7 +195,6 @@ public function getHighscorePlayers(int $offset_start = 0, int $return_amount = * * @param PlayerService $player * @return int - * @throws BindingResolutionException */ public function getHighscorePlayerRank(PlayerService $player): int { diff --git a/app/Services/MessageService.php b/app/Services/MessageService.php index 214055b5..7cdb4e62 100644 --- a/app/Services/MessageService.php +++ b/app/Services/MessageService.php @@ -2,7 +2,6 @@ namespace OGame\Services; -use Illuminate\Contracts\Container\BindingResolutionException; use OGame\Factories\GameMessageFactory; use OGame\GameMessages\Abstracts\GameMessage; use OGame\GameMessages\WelcomeMessage; @@ -170,9 +169,6 @@ public function getUnreadMessagesCount(): int ->count(); } - /** - * @throws BindingResolutionException - */ public function getUnreadMessagesCountForTab(string $tab): int { // Get all keys for the tab. @@ -184,9 +180,6 @@ public function getUnreadMessagesCountForTab(string $tab): int ->count(); } - /** - * @throws BindingResolutionException - */ public function getUnreadMessagesCountForSubTab(string $tab, string $subtab): int { // Get all keys for the subtab. diff --git a/app/Services/ObjectService.php b/app/Services/ObjectService.php index df4559c9..915489d0 100644 --- a/app/Services/ObjectService.php +++ b/app/Services/ObjectService.php @@ -124,7 +124,6 @@ public function getCivilShipObjects(): array * * @param string $machine_name * @return BuildingObject - * @throws Exception */ public function getBuildingObjectByMachineName(string $machine_name): BuildingObject { @@ -135,7 +134,7 @@ public function getBuildingObjectByMachineName(string $machine_name): BuildingOb } } - throw new Exception('Building not found'); + throw new \RuntimeException('Building not found'); } /** @@ -143,7 +142,6 @@ public function getBuildingObjectByMachineName(string $machine_name): BuildingOb * * @param string $machine_name * @return ShipObject - * @throws Exception */ public function getShipObjectByMachineName(string $machine_name): ShipObject { @@ -155,7 +153,7 @@ public function getShipObjectByMachineName(string $machine_name): ShipObject } } - throw new Exception('Ship not found'); + throw new \RuntimeException('Ship not found'); } /** @@ -163,7 +161,6 @@ public function getShipObjectByMachineName(string $machine_name): ShipObject * * @param int $object_id * @return GameObject - * @throws Exception */ public function getObjectById(int $object_id): GameObject { @@ -175,7 +172,7 @@ public function getObjectById(int $object_id): GameObject } } - throw new Exception('Game object not found with ID: ' . $object_id); + throw new \RuntimeException('Game object not found with ID: ' . $object_id); } /** @@ -183,7 +180,6 @@ public function getObjectById(int $object_id): GameObject * * @param string $machine_name * @return GameObject - * @throws Exception */ public function getObjectByMachineName(string $machine_name): GameObject { @@ -195,7 +191,7 @@ public function getObjectByMachineName(string $machine_name): GameObject } } - throw new Exception('Game object not found with machine name: ' . $machine_name); + throw new \RuntimeException('Game object not found with machine name: ' . $machine_name); } /** @@ -203,7 +199,6 @@ public function getObjectByMachineName(string $machine_name): GameObject * * @param string $machine_name * @return ResearchObject - * @throws Exception */ public function getResearchObjectByMachineName(string $machine_name): ResearchObject { @@ -215,7 +210,7 @@ public function getResearchObjectByMachineName(string $machine_name): ResearchOb } } - throw new Exception('Unit object not found with machine name: ' . $machine_name); + throw new \RuntimeException('Unit object not found with machine name: ' . $machine_name); } /** @@ -223,7 +218,6 @@ public function getResearchObjectByMachineName(string $machine_name): ResearchOb * * @param int $object_id * @return ResearchObject - * @throws Exception */ public function getResearchObjectById(int $object_id): ResearchObject { @@ -235,7 +229,7 @@ public function getResearchObjectById(int $object_id): ResearchObject } } - throw new Exception('Unit object not found with object ID: ' . $object_id); + throw new \RuntimeException('Unit object not found with object ID: ' . $object_id); } /** @@ -243,7 +237,6 @@ public function getResearchObjectById(int $object_id): ResearchObject * * @param int $object_id * @return UnitObject - * @throws Exception */ public function getUnitObjectById(int $object_id): UnitObject { @@ -254,7 +247,7 @@ public function getUnitObjectById(int $object_id): UnitObject } } - throw new Exception('Unit object not found with object ID: ' . $object_id); + throw new \RuntimeException('Unit object not found with object ID: ' . $object_id); } /** @@ -262,7 +255,6 @@ public function getUnitObjectById(int $object_id): UnitObject * * @param string $machine_name * @return UnitObject - * @throws Exception */ public function getUnitObjectByMachineName(string $machine_name): UnitObject { @@ -274,7 +266,7 @@ public function getUnitObjectByMachineName(string $machine_name): UnitObject } } - throw new Exception('Unit object not found with machine name: ' . $machine_name); + throw new \RuntimeException('Unit object not found with machine name: ' . $machine_name); } /** @@ -300,7 +292,6 @@ public function getBuildingObjectsWithProduction(): array * * @param string $machine_name * @return BuildingObject - * @throws Exception */ public function getBuildingObjectsWithProductionByMachineName(string $machine_name): BuildingObject { @@ -310,7 +301,7 @@ public function getBuildingObjectsWithProductionByMachineName(string $machine_na } } - throw new Exception('Building not found with production value for machine name: ' . $machine_name); + throw new \RuntimeException('Building not found with production value for machine name: ' . $machine_name); } /** diff --git a/app/Services/PlanetListService.php b/app/Services/PlanetListService.php index 14c14f2e..3bad19cb 100644 --- a/app/Services/PlanetListService.php +++ b/app/Services/PlanetListService.php @@ -3,7 +3,6 @@ namespace OGame\Services; use Exception; -use Illuminate\Contracts\Container\BindingResolutionException; use OGame\Factories\PlanetServiceFactory; use OGame\Models\Planet as Planet; @@ -30,11 +29,17 @@ class PlanetListService */ protected PlayerService $player; + /** + * @var PlanetServiceFactory $planetServiceFactory + */ + protected PlanetServiceFactory $planetServiceFactory; + /** * Planets constructor. */ - public function __construct(PlayerService $player) + public function __construct(PlayerService $player, PlanetServiceFactory $planetServiceFactory) { + $this->planetServiceFactory = $planetServiceFactory; $this->player = $player; $this->load($player->getId()); } @@ -44,17 +49,13 @@ public function __construct(PlayerService $player) * * @param int $id * @return void - * @throws BindingResolutionException - * @throws Exception */ public function load(int $id): void { // Get all planets of user $planets = Planet::where('user_id', $id)->get(); foreach ($planets as $record) { - $planetServiceFactory = app()->make(PlanetServiceFactory::class); - $planetService = $planetServiceFactory->makeForPlayer($this->player, $record->id); - + $planetService = $this->planetServiceFactory->makeForPlayer($this->player, $record->id); $this->planets[] = $planetService; } @@ -65,9 +66,7 @@ public function load(int $id): void // Normally it should be just the Homeworld. $planetNames = ['Homeworld', 'Colony']; for ($i = 0; $i <= (2 - count($this->planets)); $i++) { - $planetServiceFactory = app()->make(PlanetServiceFactory::class); - $planetService = $planetServiceFactory->createInitialForPlayer($this->player, $planetNames[$i]); - + $planetService = $this->planetServiceFactory->createInitialForPlayer($this->player, $planetNames[$i]); $this->planets[] = $planetService; } @@ -76,12 +75,6 @@ public function load(int $id): void $message = new MessageService($this->player); $message->sendWelcomeMessage(); } - /*if (empty($this->planets)) { - $planet = resolve('OGame\Services\PlanetService'); - $planet->create($id); - - $this->planets[] = $planet; - }*/ } /** diff --git a/app/Services/PlanetService.php b/app/Services/PlanetService.php index 2957bec6..7d912594 100644 --- a/app/Services/PlanetService.php +++ b/app/Services/PlanetService.php @@ -3,7 +3,6 @@ namespace OGame\Services; use Exception; -use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\Carbon; use OGame\Factories\PlayerServiceFactory; use OGame\GameObjects\Models\UnitCollection; @@ -52,9 +51,8 @@ class PlanetService * * @param int $planet_id * If supplied the constructor will try to load the planet from the database. - * @throws BindingResolutionException */ - public function __construct(?PlayerService $player = null, int $planet_id = 0) + public function __construct(ObjectService $objectService, PlayerServiceFactory $playerServiceFactory, ?PlayerService $player = null, int $planet_id = 0) { // Load the planet object if a positive planet ID is given. // If no planet ID is given then planet context will not be available @@ -64,7 +62,6 @@ public function __construct(?PlayerService $player = null, int $planet_id = 0) if ($player === null) { // No player has been provided, so we load it ourselves here. - $playerServiceFactory = app()->make(PlayerServiceFactory::class); $playerService = $playerServiceFactory->make($this->planet->user_id); $this->player = $playerService; } else { @@ -74,7 +71,7 @@ public function __construct(?PlayerService $player = null, int $planet_id = 0) $this->player = $player; } - $this->objects = resolve(ObjectService::class); + $this->objects = $objectService; } /** @@ -424,7 +421,7 @@ public function deductResources(Resources $resources, bool $save_planet = true): // Sanity check that this planet has enough resources, if not throw // exception. if (!$this->hasResources($resources)) { - throw new Exception('Planet does not have enough resources.'); + throw new \RuntimeException('Planet does not have enough resources.'); } if (!empty($resources->metal->get())) { @@ -470,7 +467,6 @@ public function hasResources(Resources $resources): bool * * @param UnitCollection $units * @return bool - * @throws Exception */ public function hasUnits(UnitCollection $units): bool { @@ -1530,16 +1526,17 @@ public function getPlanetMilitaryScore(): int return (int)floor($resources_spent / 1000); } - /** - * @throws BindingResolutionException - */ public function updateFleetMissions(bool $save_planet = true): void { - $fleet_missions = resolve(FleetMissionService::class); - $missions = $fleet_missions->getMissionsByPlanetId($this->getPlanetId()); + try { + $fleetMissionService = app()->make(FleetMissionService::class); + $missions = $fleetMissionService->getMissionsByPlanetId($this->getPlanetId()); - foreach ($missions as $mission) { - $fleet_missions->updateMission($mission); + foreach ($missions as $mission) { + $fleetMissionService->updateMission($mission); + } + } catch (Exception $e) { + throw new \RuntimeException('Fleet mission service not found.'); } } } diff --git a/app/Services/PlayerService.php b/app/Services/PlayerService.php index e105e4a6..095e57bc 100644 --- a/app/Services/PlayerService.php +++ b/app/Services/PlayerService.php @@ -49,9 +49,9 @@ class PlayerService * Player constructor. * * @param int $player_id - * @throws BindingResolutionException + * @param ObjectService $objectService */ - public function __construct(int $player_id) + public function __construct(int $player_id, ObjectService $objectService) { // Load the player object if a positive player ID is given. // If no player ID is given then player context will not be available, but this can be fine for unittests. @@ -59,7 +59,7 @@ public function __construct(int $player_id) $this->load($player_id); } - $this->objects = resolve('OGame\Services\ObjectService'); + $this->objects = $objectService; } /** @@ -77,7 +77,6 @@ public function equals(?PlayerService $other): bool * Load player object by user ID. * * @param int $id - * @throws BindingResolutionException */ public function load(int $id): void { @@ -98,8 +97,12 @@ public function load(int $id): void $this->setUserTech($tech); // Fetch all planets of user - $planet_list_service = app()->make(PlanetListService::class, ['player' => $this]); - $this->planets = $planet_list_service; + try { + $planet_list_service = app()->make(PlanetListService::class, ['player' => $this]); + $this->planets = $planet_list_service; + } catch (BindingResolutionException $e) { + throw new \RuntimeException('Class not found: ' . PlanetListService::class); + } } /** @@ -217,7 +220,6 @@ public function getEmail(): string * * @param string $machine_name * @return int - * @throws Exception */ public function getResearchLevel(string $machine_name): int {