From 7265eb19131e78c3f11128adce49271aea6f39ff Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 4 Jul 2017 15:43:47 -0500 Subject: [PATCH] Clean up enums and cache-keys configs --- app/Http/Controllers/Admin/RankController.php | 4 +- app/Services/PIREPService.php | 22 ++++---- app/Services/PilotService.php | 4 +- config/cache.php | 53 ++++--------------- config/enums.php | 42 ++++++--------- config/phpvms.php | 6 --- tests/PIREPTest.php | 10 ++-- 7 files changed, 45 insertions(+), 96 deletions(-) diff --git a/app/Http/Controllers/Admin/RankController.php b/app/Http/Controllers/Admin/RankController.php index a4273f3c..72b39654 100644 --- a/app/Http/Controllers/Admin/RankController.php +++ b/app/Http/Controllers/Admin/RankController.php @@ -76,7 +76,7 @@ class RankController extends BaseController $model = $this->rankRepository->create($input); Flash::success('Ranking saved successfully.'); - Cache::forget(config('phpvms.cache_keys.RANKS_PILOT_LIST')['key']); + Cache::forget(config('cache.keys.RANKS_PILOT_LIST.key')); return redirect(route('admin.ranks.edit', ['id' => $model->id])); } @@ -143,7 +143,7 @@ class RankController extends BaseController } $rank = $this->rankRepository->update($request->all(), $id); - Cache::forget(config('phpvms.cache_keys.RANKS_PILOT_LIST')['key']); + Cache::forget(config('cache.keys.RANKS_PILOT_LIST.key')); Flash::success('Ranking updated successfully.'); return redirect(route('admin.ranks.index')); diff --git a/app/Services/PIREPService.php b/app/Services/PIREPService.php index 472dbfc9..ae4cfb5a 100644 --- a/app/Services/PIREPService.php +++ b/app/Services/PIREPService.php @@ -33,13 +33,13 @@ class PIREPService extends BaseService # Figure out what default state should be. Look at the default # behavior from the rank that the pilot is assigned to - if($pirep->source == \VMSEnums::$sources['ACARS']) { + if($pirep->source == config('enums.sources.ACARS')) { $default_status = $pirep->pilot->rank->auto_approve_acars; } else { $default_status = $pirep->pilot->rank->auto_approve_manual; } - if ($default_status == \VMSEnums::$pirep_status['ACCEPTED']) { + if ($default_status == config('enums.pirep_status.ACCEPTED')) { $pirep = $this->accept($pirep); } @@ -75,10 +75,10 @@ class PIREPService extends BaseService /** * Move from a PENDING status into either ACCEPTED or REJECTED */ - if ($pirep->status == \VMSEnums::$pirep_status['PENDING']) { - if ($new_status == \VMSEnums::$pirep_status['ACCEPTED']) { + if ($pirep->status == config('enums.pirep_status.PENDING')) { + if ($new_status == config('enums.pirep_status.ACCEPTED')) { return $this->accept($pirep); - } elseif ($new_status == \VMSEnums::$pirep_status['REJECTED']) { + } elseif ($new_status == config('enums.pirep_status.REJECTED')) { return $this->reject($pirep); } else { return $pirep; @@ -88,7 +88,7 @@ class PIREPService extends BaseService /* * Move from a ACCEPTED to REJECTED status */ - elseif ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) { + elseif ($pirep->status == config('enums.pirep_status.ACCEPTED')) { $pirep = $this->reject($pirep); return $pirep; } @@ -96,7 +96,7 @@ class PIREPService extends BaseService /** * Move from REJECTED to ACCEPTED */ - elseif ($pirep->status == \VMSEnums::$pirep_status['REJECTED']) { + elseif ($pirep->status == config('enums.pirep_status.REJECTED')) { $pirep = $this->accept($pirep); return $pirep; } @@ -109,7 +109,7 @@ class PIREPService extends BaseService public function accept(Pirep &$pirep): Pirep { # moving from a REJECTED state to ACCEPTED, reconcile statuses - if ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) { + if ($pirep->status == config('enums.pirep_status.ACCEPTED')) { return $pirep; } @@ -122,7 +122,7 @@ class PIREPService extends BaseService $pirep->pilot->refresh(); # Change the status - $pirep->status = \VMSEnums::$pirep_status['ACCEPTED']; + $pirep->status = config('enums.pirep_status.ACCEPTED'); $pirep->save(); return $pirep; @@ -136,7 +136,7 @@ class PIREPService extends BaseService { # If this was previously ACCEPTED, then reconcile the flight hours # that have already been counted, etc - if ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) { + if ($pirep->status == config('enums.pirep_status.ACCEPTED')) { $pilot = $pirep->pilot; $ft = $pirep->flight_time * -1; @@ -147,7 +147,7 @@ class PIREPService extends BaseService } # Change the status - $pirep->status = \VMSEnums::$pirep_status['REJECTED']; + $pirep->status = config('enums.pirep_status.REJECTED'); $pirep->save(); return $pirep; diff --git a/app/Services/PilotService.php b/app/Services/PilotService.php index d0be2344..336151a7 100644 --- a/app/Services/PilotService.php +++ b/app/Services/PilotService.php @@ -36,8 +36,8 @@ class PilotService extends BaseService # TODO: Cache $ranks = Cache::remember( - config('phpvms.cache_keys.RANKS_PILOT_LIST')['key'], - config('phpvms.cache_keys.RANKS_PILOT_LIST')['time'], + config('cache.keys.RANKS_PILOT_LIST.key'), + config('cache.keys.RANKS_PILOT_LIST.time'), function () { return Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get(); }); diff --git a/config/cache.php b/config/cache.php index 8b1fd7fc..27012280 100755 --- a/config/cache.php +++ b/config/cache.php @@ -2,42 +2,20 @@ return [ - /* - |-------------------------------------------------------------------------- - | Default Cache Store - |-------------------------------------------------------------------------- - | - | This option controls the default cache connection that gets used while - | using this caching library. This connection is used when another is - | not explicitly specified when executing a given caching function. - | - | Supported: "apc", "array", "database", "file", "memcached", "redis" - | - */ - 'default' => env('CACHE_DRIVER', 'file'), + 'prefix' => env('CACHE_PREFIX', ''), - /* - |-------------------------------------------------------------------------- - | Cache Stores - |-------------------------------------------------------------------------- - | - | Here you may define all of the cache "stores" for your application as - | well as their drivers. You may even define multiple stores for the - | same cache driver to group types of items stored in your caches. - | - */ + 'keys' => [ + 'RANKS_PILOT_LIST' => [ + 'key' => 'ranks::pilot_list', + 'time' => 1440, + ] + ], 'stores' => [ - 'apc' => [ - 'driver' => 'apc', - ], - - 'array' => [ - 'driver' => 'array', - ], - + 'apc' => ['driver' => 'apc'], + 'array' => ['driver' => 'array'], 'database' => [ 'driver' => 'database', 'table' => 'cache', @@ -74,17 +52,4 @@ return [ ], ], - - /* - |-------------------------------------------------------------------------- - | Cache Key Prefix - |-------------------------------------------------------------------------- - | - | When utilizing a RAM based store such as APC or Memcached, there might - | be other applications utilizing the same cache. So, we'll specify a - | value to get prefixed to all our keys so we can avoid collisions. - | - */ - - 'prefix' => env('CACHE_PREFIX', ''), ]; diff --git a/config/enums.php b/config/enums.php index 1f8305d4..74213744 100644 --- a/config/enums.php +++ b/config/enums.php @@ -1,31 +1,21 @@ [ + 'MANUAL' => 0, + 'ACARS' => 1, + ], -class VMSEnums -{ - public static $sources - = [ - 'MANUAL' => 0, - 'ACARS' => 1, - ]; + 'pirep_status' => [ + 'PENDING' => 0, + 'ACCEPTED' => 1, + 'REJECTED' => -1, + ], - public static $pirep_status - = [ - 'PENDING' => 0, - 'ACCEPTED' => 1, - 'REJECTED' => -1, - ]; + 'fuel_types' => [ + '100LL' => 0, + 'JETA' => 1, + 'MOGAS' => 2, + ], +]; - public static $fuel_types - = [ - '100LL' => 0, - 'JETA' => 1, - 'MOGAS' => 2, - ]; -} diff --git a/config/phpvms.php b/config/phpvms.php index 4903fa14..39459741 100644 --- a/config/phpvms.php +++ b/config/phpvms.php @@ -8,10 +8,4 @@ return [ */ 'currency' => env('PHPVMS_CURRENCY', 'dollar'), - 'cache_keys' => [ - 'RANKS_PILOT_LIST' => [ - 'key' => 'ranks::pilot_list', - 'time' => 1440, - ] - ] ]; diff --git a/tests/PIREPTest.php b/tests/PIREPTest.php index 1facb8d3..c224ec01 100644 --- a/tests/PIREPTest.php +++ b/tests/PIREPTest.php @@ -39,7 +39,7 @@ class PIREPTest extends TestCase $pirep = $this->pirepSvc->create($pirep, []); if($accept) { $this->pirepSvc->changeStatus($pirep, - VMSEnums::$pirep_status['ACCEPTED']); + config('enums.pirep_status.ACCEPTED')); } } @@ -69,12 +69,12 @@ class PIREPTest extends TestCase * Check the initial status info */ $this->assertEquals($pirep->pilot->flights, 0); - $this->assertEquals($pirep->status, VMSEnums::$pirep_status['PENDING']); + $this->assertEquals($pirep->status, config('enums.pirep_status.PENDING')); /** * Now set the PIREP state to ACCEPTED */ - $this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['ACCEPTED']); + $this->pirepSvc->changeStatus($pirep, config('enums.pirep_status.ACCEPTED')); $this->assertEquals(1, $pirep->pilot->flights); $this->assertEquals(21600, $pirep->pilot->flight_time); $this->assertEquals(1, $pirep->pilot->rank_id); @@ -82,7 +82,7 @@ class PIREPTest extends TestCase /** * Now go from ACCEPTED to REJECTED */ - $this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['REJECTED']); + $this->pirepSvc->changeStatus($pirep, config('enums.pirep_status.REJECTED')); $this->assertEquals(0, $pirep->pilot->flights); $this->assertEquals(0, $pirep->pilot->flight_time); $this->assertEquals(1, $pirep->pilot->rank_id); @@ -117,7 +117,7 @@ class PIREPTest extends TestCase # The PIREP should have been automatically accepted $this->assertEquals( - VMSEnums::$pirep_status['ACCEPTED'], + config('enums.pirep_status.ACCEPTED'), $latest_pirep->status ); }