From 2c5e69dc499bb0237736ec2a9cf1c7995572a02d Mon Sep 17 00:00:00 2001
From: Alex Toff <me@alextoff.uk>
Date: Wed, 1 Apr 2020 12:15:17 +0100
Subject: [PATCH] Add catch for VATSIM XML downtime

---
 src/StandStatus.php | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/StandStatus.php b/src/StandStatus.php
index 6fe8649..170918c 100644
--- a/src/StandStatus.php
+++ b/src/StandStatus.php
@@ -6,9 +6,9 @@
     class StandStatus
     {
 
-        public $stands = array();
-        public $occupiedStands = array();
-        public $aircraftSearchResults;
+        public $stands = [];
+        public $occupiedStands = [];
+        public $aircraftSearchResults = [];
 
         /*
          Airport Stand Details
@@ -89,7 +89,7 @@ public function allStandsPaginationArray($pageLimit)
         {
             // Work out the ammount of pages
             $noOfPages = ceil(count($this->stands) / $pageLimit);
-            $pageinationArray = array();
+            $pageinationArray = [];
             for ($i = 0; $i < $noOfPages; $i++) {
                 $pageinationArray[] = $this->allStands($i, $pageLimit);
             }
@@ -110,7 +110,7 @@ function parseData()
         // Load the stand data
         function loadStandsData()
         {
-            $array = $fields = array();
+            $array = $fields = [];
             $i = 0;
             $handle = @fopen($this->airportStandsFile, "r");
             if ($handle) {
@@ -149,7 +149,11 @@ function getAircraftWithinParameters()
             $vatsim = new VatsimData();
             $vatsim->loadData();
 
-            $pilots = $vatsim->getPilots()->toArray();
+            try {
+                $pilots = $vatsim->getPilots()->toArray();
+            }catch (Exception $e){
+                return false;
+            }
 
             // INSERT TEST PILOTS
             //$pilots[] = array('callsign' => "TEST", "latitude" => 55.949228, "longitude" => -3.364303, "altitude" => 0, "groundspeed" => 0, "planned_destairport" => "TEST", "planned_depairport" => "TEST");
@@ -162,7 +166,7 @@ function getAircraftWithinParameters()
             }
 
 
-            $filteredResults = array();
+            $filteredResults = ;
             foreach ($pilots as $pilot) {
                 if (($this->getCoordDistance($pilot['latitude'], $pilot['longitude'], $this->airportCoordinates['lat'], $this->airportCoordinates['long']) < $this->maxDistanceFromAirport)) {
                     if (($pilot['groundspeed'] <= $this->maxAircraftGroundspeed) && ($pilot['altitude'] <= $this->maxAircraftAltitude)) {
@@ -184,7 +188,7 @@ function checkIfAircraftAreOnStand()
             foreach ($pilots as $pilot) {
 
                 // Array to hold the stands they could possibly be on
-                $possibleStands = array();
+                $possibleStands = ;
 
                 // Check each stand to see how close they are
                 foreach ($stands as $stand) {
@@ -305,7 +309,7 @@ function unsetStandOccupied($standID)
 
         function standSides($standID)
         {
-            $standSides = array();
+            $standSides = ;
             $stands = $this->stands;
 
             //Find the 'base' stand number