From c4206b4727885689af51f2c3d1b50cdb45fbe11d Mon Sep 17 00:00:00 2001 From: DaGeek Date: Tue, 13 Oct 2020 19:52:40 +0100 Subject: [PATCH 1/5] Adding a new AwardClass for Flight Time This award is based on the original PilotFlightAwards.php file but checks the Pilots Flight Time (In Minutes). This award means you can create an award for a pilot that completes any amount of flight time (In Minutes). --- modules/Awards/Awards/PilotHoursAwards.php | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/Awards/Awards/PilotHoursAwards.php diff --git a/modules/Awards/Awards/PilotHoursAwards.php b/modules/Awards/Awards/PilotHoursAwards.php new file mode 100644 index 000000000..00a307d39 --- /dev/null +++ b/modules/Awards/Awards/PilotHoursAwards.php @@ -0,0 +1,54 @@ +user->flight_time >= $flight_minutes; + } +} From 1d54cf99f6273b0802d5c473ca36ac45a9b698a4 Mon Sep 17 00:00:00 2001 From: DaGeek Date: Tue, 13 Oct 2020 20:02:37 +0100 Subject: [PATCH 2/5] Update PilotHoursAwards.php Small Correction suggested via Review, to check that that value of $flight_minutes is infact an int --- modules/Awards/Awards/PilotHoursAwards.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Awards/Awards/PilotHoursAwards.php b/modules/Awards/Awards/PilotHoursAwards.php index 00a307d39..35ffd16de 100644 --- a/modules/Awards/Awards/PilotHoursAwards.php +++ b/modules/Awards/Awards/PilotHoursAwards.php @@ -49,6 +49,6 @@ public function check($flight_minutes = null): bool $flight_minutes = 99999; } - return $this->user->flight_time >= $flight_minutes; + return $this->user->flight_time >= (int) $flight_minutes; } } From f9b0aeb34d754c93ffdd7e8b416faa5fe7d604f7 Mon Sep 17 00:00:00 2001 From: DaGeek Date: Tue, 13 Oct 2020 21:42:55 +0100 Subject: [PATCH 3/5] Update PilotHoursAwards.php added an additional check that $flight_minutes is an int if provided by the user. --- modules/Awards/Awards/PilotHoursAwards.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/Awards/Awards/PilotHoursAwards.php b/modules/Awards/Awards/PilotHoursAwards.php index 35ffd16de..6fcbaa90a 100644 --- a/modules/Awards/Awards/PilotHoursAwards.php +++ b/modules/Awards/Awards/PilotHoursAwards.php @@ -48,6 +48,9 @@ public function check($flight_minutes = null): bool if (!$flight_minutes) { $flight_minutes = 99999; } + if (!is_int($flight_minutes)) { + return false; + } return $this->user->flight_time >= (int) $flight_minutes; } From 03ebbfa988dfed539776c5db7c929491852b0a5e Mon Sep 17 00:00:00 2001 From: DaGeek Date: Tue, 13 Oct 2020 21:48:43 +0100 Subject: [PATCH 4/5] Update PilotHoursAwards.php Added the Log function if the user enters a non int value in the ui --- modules/Awards/Awards/PilotHoursAwards.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/Awards/Awards/PilotHoursAwards.php b/modules/Awards/Awards/PilotHoursAwards.php index 6fcbaa90a..dbc00f8be 100644 --- a/modules/Awards/Awards/PilotHoursAwards.php +++ b/modules/Awards/Awards/PilotHoursAwards.php @@ -3,6 +3,7 @@ namespace Modules\Awards\Awards; use App\Contracts\Award; +use Log; /** * All award classes need to extend Award and implement the check() method @@ -49,6 +50,7 @@ public function check($flight_minutes = null): bool $flight_minutes = 99999; } if (!is_int($flight_minutes)) { + Log::error('PilotHourAwards: Flight time "'.$flight_minutes.'" is not a valid flight time'); return false; } From a189302617971fa6342f89cd2459ae696fc099ad Mon Sep 17 00:00:00 2001 From: DaGeek Date: Tue, 13 Oct 2020 21:53:22 +0100 Subject: [PATCH 5/5] Update PilotHoursAwards.php Cleaning up some unneeded code due to the new input validation based on is_int() --- modules/Awards/Awards/PilotHoursAwards.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/Awards/Awards/PilotHoursAwards.php b/modules/Awards/Awards/PilotHoursAwards.php index dbc00f8be..c7695b370 100644 --- a/modules/Awards/Awards/PilotHoursAwards.php +++ b/modules/Awards/Awards/PilotHoursAwards.php @@ -36,19 +36,12 @@ class PilotHoursAwards extends Award /** * If the user has over N minutes of flights, then we can give them this award. * - * If no parameter is passed in, just default it to 99999. You should check if there - * is a parameter or not. You can call it whatever you want, since that would make - * sense with the $param_description. - * * @param int|null $flight_minutes The parameters passed in from the UI * * @return bool */ public function check($flight_minutes = null): bool { - if (!$flight_minutes) { - $flight_minutes = 99999; - } if (!is_int($flight_minutes)) { Log::error('PilotHourAwards: Flight time "'.$flight_minutes.'" is not a valid flight time'); return false;