Skip to content

Commit

Permalink
Make sure report model is loaded before accessing props
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Feb 14, 2025
1 parent b37dc68 commit 6758cb6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/GameMessages/BattleReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function getSubject(): string
*/
public function getBody(): string
{
$this->loadBattleReportModel();

// Load planet by coordinate.
$coordinate = new Coordinate($this->battleReportModel->planet_galaxy, $this->battleReportModel->planet_system, $this->battleReportModel->planet_position);
$planet = $this->planetServiceFactory->makeForCoordinate($coordinate, true, PlanetType::from($this->battleReportModel->planet_type));
Expand All @@ -91,6 +93,8 @@ public function getBody(): string
*/
public function getBodyFull(): string
{
$this->loadBattleReportModel();

// Load planet by coordinate.
$coordinate = new Coordinate($this->battleReportModel->planet_galaxy, $this->battleReportModel->planet_system, $this->battleReportModel->planet_position);
$planet = $this->planetServiceFactory->makeForCoordinate($coordinate, true, PlanetType::from($this->battleReportModel->planet_type));
Expand Down Expand Up @@ -126,6 +130,7 @@ public function getFooterDetails(): string
*/
private function getBattleReportParams(): array
{
// Sanity check to make sure the battle report model is loaded.
$this->loadBattleReportModel();

// TODO: add feature test for code below and check edgecases, such as when the planet has been deleted and
Expand Down
5 changes: 5 additions & 0 deletions app/GameMessages/EspionageReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function getSubject(): string
*/
public function getBody(): string
{
$this->loadEspionageReportModel();

// Load planet by coordinate.
$coordinate = new Coordinate($this->espionageReportModel->planet_galaxy, $this->espionageReportModel->planet_system, $this->espionageReportModel->planet_position);
$planet = $this->planetServiceFactory->makeForCoordinate($coordinate, true, PlanetType::from($this->espionageReportModel->planet_type));
Expand All @@ -87,6 +89,8 @@ public function getBody(): string
*/
public function getBodyFull(): string
{
$this->loadEspionageReportModel();

// Load planet by coordinate.
$coordinate = new Coordinate($this->espionageReportModel->planet_galaxy, $this->espionageReportModel->planet_system, $this->espionageReportModel->planet_position);
$planet = $this->planetServiceFactory->makeForCoordinate($coordinate, true, PlanetType::from($this->espionageReportModel->planet_type));
Expand Down Expand Up @@ -119,6 +123,7 @@ public function getFooterDetails(): string
*/
private function getEspionageReportParams(): array
{
// Sanity check to make sure the espionage report model is loaded.
$this->loadEspionageReportModel();

// TODO: add feature test for code below and check edgecases, such as when the planet has been deleted and
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/MessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public function testBattleReportWithDeletedPlayers(): void
'shielding_technology' => 0,
'armor_technology' => 0,
];
// ... rest of battle report setup ...

// Create message with this battle report
$message = new Message();
Expand Down

0 comments on commit 6758cb6

Please sign in to comment.