From 0cb27ffa108aabe5c9a20ab9365f6896a31efeb2 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Mon, 22 Apr 2024 18:52:22 +0100 Subject: [PATCH] fix: cargo allocator crash when cargo flight but no airline --- .../Stand/CargoFlightPreferredArrivalStandAllocator.php | 7 ++++++- .../CargoFlightPreferredArrivalStandAllocatorTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocator.php b/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocator.php index 8b7272bf9..374b71baf 100644 --- a/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocator.php +++ b/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocator.php @@ -29,11 +29,16 @@ public function __construct(AirlineService $airlineService) public function allocate(NetworkAircraft $aircraft): ?int { - // If the aircraft doesnt have an airline, we cant allocate a stand + // If the aircraft isn't a cargo airline or a cargo flight, this rule doesn't apply if (!$this->isCargoAirline($aircraft) && !$this->isCargoFlight($aircraft)) { return null; } + // If the aircarft has no airline at all, there's nothing we can do + if ($aircraft->airline_id === null) { + return null; + } + return $this->selectAirlineSpecificStands( $aircraft, $this->queryFilter() diff --git a/tests/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocatorTest.php b/tests/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocatorTest.php index 70ea75896..7c59e979e 100644 --- a/tests/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocatorTest.php +++ b/tests/app/Allocator/Stand/CargoFlightPreferredArrivalStandAllocatorTest.php @@ -131,6 +131,14 @@ public function testItDoesntAllocateCargoStandsIfNoAirline() $this->assertNull($allocation); } + public function testItDoesntAllocateCargoStandsIfNoAirlineButIsCargoFlight() + { + $aircraft = $this->createAircraft('ABCDEF', 'EGLL'); + $aircraft->remarks = 'Some stuff RMK/CARGO Some more stuff'; + $allocation = $this->allocator->allocate($aircraft); + $this->assertNull($allocation); + } + public function testItDoesntRankStandsIfUnknownAircraft() { $aircraft = $this->newAircraft('BAW1234', 'EGLL', 'C172');