Clean up enums and cache-keys configs

This commit is contained in:
Nabeel Shahzad 2017-07-04 15:43:47 -05:00
parent 870eefb83d
commit 7265eb1913
7 changed files with 45 additions and 96 deletions

View File

@ -76,7 +76,7 @@ class RankController extends BaseController
$model = $this->rankRepository->create($input); $model = $this->rankRepository->create($input);
Flash::success('Ranking saved successfully.'); 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])); return redirect(route('admin.ranks.edit', ['id' => $model->id]));
} }
@ -143,7 +143,7 @@ class RankController extends BaseController
} }
$rank = $this->rankRepository->update($request->all(), $id); $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.'); Flash::success('Ranking updated successfully.');
return redirect(route('admin.ranks.index')); return redirect(route('admin.ranks.index'));

View File

@ -33,13 +33,13 @@ class PIREPService extends BaseService
# Figure out what default state should be. Look at the default # Figure out what default state should be. Look at the default
# behavior from the rank that the pilot is assigned to # 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; $default_status = $pirep->pilot->rank->auto_approve_acars;
} else { } else {
$default_status = $pirep->pilot->rank->auto_approve_manual; $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); $pirep = $this->accept($pirep);
} }
@ -75,10 +75,10 @@ class PIREPService extends BaseService
/** /**
* Move from a PENDING status into either ACCEPTED or REJECTED * Move from a PENDING status into either ACCEPTED or REJECTED
*/ */
if ($pirep->status == \VMSEnums::$pirep_status['PENDING']) { if ($pirep->status == config('enums.pirep_status.PENDING')) {
if ($new_status == \VMSEnums::$pirep_status['ACCEPTED']) { if ($new_status == config('enums.pirep_status.ACCEPTED')) {
return $this->accept($pirep); return $this->accept($pirep);
} elseif ($new_status == \VMSEnums::$pirep_status['REJECTED']) { } elseif ($new_status == config('enums.pirep_status.REJECTED')) {
return $this->reject($pirep); return $this->reject($pirep);
} else { } else {
return $pirep; return $pirep;
@ -88,7 +88,7 @@ class PIREPService extends BaseService
/* /*
* Move from a ACCEPTED to REJECTED status * 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); $pirep = $this->reject($pirep);
return $pirep; return $pirep;
} }
@ -96,7 +96,7 @@ class PIREPService extends BaseService
/** /**
* Move from REJECTED to ACCEPTED * Move from REJECTED to ACCEPTED
*/ */
elseif ($pirep->status == \VMSEnums::$pirep_status['REJECTED']) { elseif ($pirep->status == config('enums.pirep_status.REJECTED')) {
$pirep = $this->accept($pirep); $pirep = $this->accept($pirep);
return $pirep; return $pirep;
} }
@ -109,7 +109,7 @@ class PIREPService extends BaseService
public function accept(Pirep &$pirep): Pirep public function accept(Pirep &$pirep): Pirep
{ {
# moving from a REJECTED state to ACCEPTED, reconcile statuses # 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; return $pirep;
} }
@ -122,7 +122,7 @@ class PIREPService extends BaseService
$pirep->pilot->refresh(); $pirep->pilot->refresh();
# Change the status # Change the status
$pirep->status = \VMSEnums::$pirep_status['ACCEPTED']; $pirep->status = config('enums.pirep_status.ACCEPTED');
$pirep->save(); $pirep->save();
return $pirep; return $pirep;
@ -136,7 +136,7 @@ class PIREPService extends BaseService
{ {
# If this was previously ACCEPTED, then reconcile the flight hours # If this was previously ACCEPTED, then reconcile the flight hours
# that have already been counted, etc # that have already been counted, etc
if ($pirep->status == \VMSEnums::$pirep_status['ACCEPTED']) { if ($pirep->status == config('enums.pirep_status.ACCEPTED')) {
$pilot = $pirep->pilot; $pilot = $pirep->pilot;
$ft = $pirep->flight_time * -1; $ft = $pirep->flight_time * -1;
@ -147,7 +147,7 @@ class PIREPService extends BaseService
} }
# Change the status # Change the status
$pirep->status = \VMSEnums::$pirep_status['REJECTED']; $pirep->status = config('enums.pirep_status.REJECTED');
$pirep->save(); $pirep->save();
return $pirep; return $pirep;

View File

@ -36,8 +36,8 @@ class PilotService extends BaseService
# TODO: Cache # TODO: Cache
$ranks = Cache::remember( $ranks = Cache::remember(
config('phpvms.cache_keys.RANKS_PILOT_LIST')['key'], config('cache.keys.RANKS_PILOT_LIST.key'),
config('phpvms.cache_keys.RANKS_PILOT_LIST')['time'], config('cache.keys.RANKS_PILOT_LIST.time'),
function () { function () {
return Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get(); return Rank::where('auto_promote', true)->orderBy('hours', 'asc')->get();
}); });

View File

@ -2,42 +2,20 @@
return [ 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'), 'default' => env('CACHE_DRIVER', 'file'),
'prefix' => env('CACHE_PREFIX', ''),
/* 'keys' => [
|-------------------------------------------------------------------------- 'RANKS_PILOT_LIST' => [
| Cache Stores 'key' => 'ranks::pilot_list',
|-------------------------------------------------------------------------- 'time' => 1440,
| ]
| 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.
|
*/
'stores' => [ 'stores' => [
'apc' => [ 'apc' => ['driver' => 'apc'],
'driver' => 'apc', 'array' => ['driver' => 'array'],
],
'array' => [
'driver' => 'array',
],
'database' => [ 'database' => [
'driver' => 'database', 'driver' => 'database',
'table' => 'cache', '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', ''),
]; ];

View File

@ -1,31 +1,21 @@
<?php <?php
# TODO: Remove this ugly hackiness return [
if(defined('VMSEnums')) { 'sources' => [
return;
} else {
define('VMSEnums', true);
}
class VMSEnums
{
public static $sources
= [
'MANUAL' => 0, 'MANUAL' => 0,
'ACARS' => 1, 'ACARS' => 1,
]; ],
public static $pirep_status 'pirep_status' => [
= [
'PENDING' => 0, 'PENDING' => 0,
'ACCEPTED' => 1, 'ACCEPTED' => 1,
'REJECTED' => -1, 'REJECTED' => -1,
]; ],
public static $fuel_types 'fuel_types' => [
= [
'100LL' => 0, '100LL' => 0,
'JETA' => 1, 'JETA' => 1,
'MOGAS' => 2, 'MOGAS' => 2,
]; ],
} ];

View File

@ -8,10 +8,4 @@ return [
*/ */
'currency' => env('PHPVMS_CURRENCY', 'dollar'), 'currency' => env('PHPVMS_CURRENCY', 'dollar'),
'cache_keys' => [
'RANKS_PILOT_LIST' => [
'key' => 'ranks::pilot_list',
'time' => 1440,
]
]
]; ];

View File

@ -39,7 +39,7 @@ class PIREPTest extends TestCase
$pirep = $this->pirepSvc->create($pirep, []); $pirep = $this->pirepSvc->create($pirep, []);
if($accept) { if($accept) {
$this->pirepSvc->changeStatus($pirep, $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 * Check the initial status info
*/ */
$this->assertEquals($pirep->pilot->flights, 0); $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 * 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(1, $pirep->pilot->flights);
$this->assertEquals(21600, $pirep->pilot->flight_time); $this->assertEquals(21600, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id); $this->assertEquals(1, $pirep->pilot->rank_id);
@ -82,7 +82,7 @@ class PIREPTest extends TestCase
/** /**
* Now go from ACCEPTED to REJECTED * 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->flights);
$this->assertEquals(0, $pirep->pilot->flight_time); $this->assertEquals(0, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id); $this->assertEquals(1, $pirep->pilot->rank_id);
@ -117,7 +117,7 @@ class PIREPTest extends TestCase
# The PIREP should have been automatically accepted # The PIREP should have been automatically accepted
$this->assertEquals( $this->assertEquals(
VMSEnums::$pirep_status['ACCEPTED'], config('enums.pirep_status.ACCEPTED'),
$latest_pirep->status $latest_pirep->status
); );
} }