Skip to content

Commit

Permalink
Code style refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed May 24, 2024
1 parent 23495bf commit 05c2ed5
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 34 deletions.
2 changes: 2 additions & 0 deletions app/Factories/GameMissionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static function getMissionById(int $missionId, array $dependencies): Game
return app()->make(EspionageMission::class, $dependencies);
case 7:
return app()->make(ColonisationMission::class, $dependencies);
default:
throw new \RuntimeException('Mission not found: ' . $missionId);
}
} catch (BindingResolutionException $e) {
throw new \RuntimeException('Class not found: ' . PlayerService::class);
Expand Down
14 changes: 7 additions & 7 deletions app/GameMessages/Abstracts/GameMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public function isUnread(): bool
}

/**
* Get the key of the message.
* Get the ID of the message.
*
* @return string
* @return int
*/
public function getId(): string
public function getId(): int
{
return $this->message->id;
}
Expand Down Expand Up @@ -185,8 +185,8 @@ public function getFooterDetails(): string
/**
* Check the provided params and fill in missing ones with "?undefined?".
*
* @param array $params
* @return array<int, string>
* @param array<string, string> $params
* @return array<string, string>
*/
private function checkParams(array $params): array
{
Expand All @@ -204,8 +204,8 @@ private function checkParams(array $params): array
/**
* Format reserved params such as resources.
*
* @param array $params
* @return array
* @param array<string, string> $params
* @return array<string, string>
*/
private function formatReservedParams(array $params): array
{
Expand Down
3 changes: 1 addition & 2 deletions app/GameMessages/EspionageReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ private function loadEspionageReportModel(): void
if ($espionageReport === null) {
// If espionage report is not found, we use an empty model. This is for testing purposes.
$this->espionageReportModel = new \OGame\Models\EspionageReport();
}
else {
} else {
$this->espionageReportModel = $espionageReport;
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/GameMissions/EspionageMission.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ private function createEspionageReport(PlanetService $planet): int
$report->planet_user_id = $planet->getPlayer()->getId();

$report->player_info = [
'player_id' => $planet->getPlayer()->getId(),
'player_id' => (string)$planet->getPlayer()->getId(),
'player_name' => $planet->getPlayer()->getUsername(),
];

// Resources
$report->resources = [
'metal' => $planet->metal()->get(),
'crystal' => $planet->crystal()->get(),
'deuterium' => $planet->deuterium()->get(),
'energy' => $planet->energy()->get()
'metal' => (int)$planet->metal()->get(),
'crystal' => (int)$planet->crystal()->get(),
'deuterium' => (int)$planet->deuterium()->get(),
'energy' => (int)$planet->energy()->get()
];

// TODO: implement logic which determines what to include in the espionage report based on
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public function ajaxGetTabContents(Request $request, MessageService $messageServ
/**
* Returns an individual message for a full screen view.
*
* @param string $messageId
* @param int $messageId
* @param MessageService $messageService
* @return View
*/
public function ajaxGetMessage(string $messageId, MessageService $messageService): View
public function ajaxGetMessage(int $messageId, MessageService $messageService): View
{
// Get full message view model.
$messageObject = $messageService->getFullMessage($messageId);
Expand Down
2 changes: 1 addition & 1 deletion app/Services/MessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public function sendSystemMessageToPlayer(PlayerService $player, string $gameMes
throw new \InvalidArgumentException('Invalid game message class.');
}

/** @var GameMessage $gameMessage */
try {
/** @var GameMessage $gameMessage */
$gameMessage = app()->make($gameMessageClass);

$message = new Message();
Expand Down
3 changes: 1 addition & 2 deletions tests/AccountTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ protected function playerSetResearchLevel(string $machine_name, int $object_leve
$playerService = app()->make(PlayerService::class, ['player_id' => $this->currentUserId]);
// Update the technology level for the player.
$playerService->setResearchLevel($machine_name, $object_level, true);
}
catch (Exception $e) {
} catch (Exception $e) {
$this->fail('Failed to set research level for player. Error: ' . $e->getMessage());
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/FleetDispatch/FleetDispatchColoniseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public function testDispatchFleetColonizeEmptyPlanet(): void
// Assert that the new planet has been created.
try {
$planetServiceFactory = app()->make(PlanetServiceFactory::class);
}
catch (BindingResolutionException $e) {
} catch (BindingResolutionException $e) {
$this->fail('PlanetServiceFactory cannot be resolved from the container.');
}
$newPlanet = $planetServiceFactory->makeForCoordinate($newPlanetCoordinates);
Expand Down
9 changes: 3 additions & 6 deletions tests/Feature/FleetDispatch/FleetDispatchTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ public function testDispatchFleetRecallMission(): void
// Get just dispatched fleet mission ID from database.
try {
$fleetMissionService = app()->make(FleetMissionService::class, ['player' => $this->planetService->getPlayer()]);
}
catch (BindingResolutionException $e) {
} catch (BindingResolutionException $e) {
$this->fail('Failed to resolve FleetMissionService in testDispatchFleetRecallMission.');
}
$fleetMission = $fleetMissionService->getActiveFleetMissionsForCurrentPlayer()->first();
Expand Down Expand Up @@ -357,8 +356,7 @@ public function testDispatchFleetRecallMission(): void

try {
$fleetMissionService = app()->make(FleetMissionService::class, ['player' => $this->planetService->getPlayer()]);
}
catch (BindingResolutionException $e) {
} catch (BindingResolutionException $e) {
$this->fail('Failed to resolve FleetMissionService in testDispatchFleetRecallMission.');
}
$fleetMission = $fleetMissionService->getActiveFleetMissionsForCurrentPlayer()->first();
Expand Down Expand Up @@ -410,8 +408,7 @@ public function testDispatchFleetRecallMissionTwiceError(): void
// Get just dispatched fleet mission ID from database.
try {
$fleetMissionService = app()->make(FleetMissionService::class, ['player' => $this->planetService->getPlayer()]);
}
catch (BindingResolutionException $e) {
} catch (BindingResolutionException $e) {
$this->fail('Failed to resolve FleetMissionService in testDispatchFleetRecallMission.');
}
$fleetMission = $fleetMissionService->getActiveFleetMissionsForCurrentPlayer()->first();
Expand Down
12 changes: 5 additions & 7 deletions tests/Feature/MessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use OGame\Models\EspionageReport;
use OGame\Models\Message;
use OGame\Services\MessageService;
use OGame\Services\PlanetService;
use Tests\AccountTestCase;

/**
Expand Down Expand Up @@ -56,12 +55,12 @@ public function testGameMessages(): void
$message->params = $filledParams;

// Check that the message has a valid subject and body defined.
$this->assertNotEmpty($gameMessage->getSubject($message), 'Subject is empty for ' . get_class($gameMessage));
$this->assertNotEmpty($gameMessage->getBody($message), 'Body is empty for ' . get_class($gameMessage));
$this->assertNotEmpty($gameMessage->getSubject(), 'Subject is empty for ' . get_class($gameMessage));
$this->assertNotEmpty($gameMessage->getBody(), 'Body is empty for ' . get_class($gameMessage));

// Also assert that it does not contains "t_messages" string as this indicates the translation is missing.
$this->assertStringNotContainsString('t_messages', $gameMessage->getSubject($message), 'Subject contains t_messages for ' . get_class($gameMessage));
$this->assertStringNotContainsString('t_messages', $gameMessage->getBody($message), 'Body contains t_messages for ' . get_class($gameMessage));
$this->assertStringNotContainsString('t_messages', $gameMessage->getSubject(), 'Subject contains t_messages for ' . get_class($gameMessage));
$this->assertStringNotContainsString('t_messages', $gameMessage->getBody(), 'Body contains t_messages for ' . get_class($gameMessage));
}
}

Expand All @@ -72,8 +71,7 @@ public function testEspionageReport(): void
{
try {
$messageService = app()->make(MessageService::class);
}
catch (BindingResolutionException $e) {
} catch (BindingResolutionException $e) {
$this->fail('Failed to resolve MessageService in testEspionageReport.');
}
// Create a new espionage report record in the db and set the espionage_report_id to its ID.
Expand Down

0 comments on commit 05c2ed5

Please sign in to comment.