Replace magic numbers with constants (#754)

* Replace magic numbers with constants
This commit is contained in:
Lance Pioch 2017-11-12 18:16:54 -05:00 committed by Dane Everitt
parent 6043114f38
commit f94e4c15b0
3 changed files with 10 additions and 3 deletions

View file

@ -15,6 +15,8 @@ use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
class CleanServiceBackupFilesCommand extends Command class CleanServiceBackupFilesCommand extends Command
{ {
const BACKUP_THRESHOLD_MINUTES = 5;
/** /**
* @var \Carbon\Carbon * @var \Carbon\Carbon
*/ */
@ -58,7 +60,7 @@ class CleanServiceBackupFilesCommand extends Command
collect($files)->each(function ($file) { collect($files)->each(function ($file) {
$lastModified = $this->carbon->timestamp($this->disk->lastModified($file)); $lastModified = $this->carbon->timestamp($this->disk->lastModified($file));
if ($lastModified->diffInMinutes($this->carbon->now()) > 5) { if ($lastModified->diffInMinutes($this->carbon->now()) > self::BACKUP_THRESHOLD_MINUTES) {
$this->disk->delete($file); $this->disk->delete($file);
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file])); $this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file]));
} }

View file

@ -18,6 +18,9 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
{ {
use Searchable; use Searchable;
const THRESHOLD_PERCENTAGE_LOW = 75;
const THRESHOLD_PERCENTAGE_MEDIUM = 90;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -56,7 +59,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
'value' => number_format($value), 'value' => number_format($value),
'max' => number_format($maxUsage), 'max' => number_format($maxUsage),
'percent' => $percent, 'percent' => $percent,
'css' => ($percent <= 75) ? 'green' : (($percent > 90) ? 'red' : 'yellow'), 'css' => ($percent <= self::THRESHOLD_PERCENTAGE_LOW) ? 'green' : (($percent > self::THRESHOLD_PERCENTAGE_MEDIUM) ? 'red' : 'yellow'),
], ],
]; ];
}) })

View file

@ -16,6 +16,8 @@ use Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException;
class TaskCreationService class TaskCreationService
{ {
const MAX_INTERVAL_TIME_SECONDS = 900;
/** /**
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface * @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
*/ */
@ -50,7 +52,7 @@ class TaskCreationService
$schedule = ($schedule instanceof Schedule) ? $schedule->id : $schedule; $schedule = ($schedule instanceof Schedule) ? $schedule->id : $schedule;
$delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value']; $delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value'];
if ($delay > 900) { if ($delay > self::MAX_INTERVAL_TIME_SECONDS) {
throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long')); throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long'));
} }