Skip to content

Commit f94e4c1

Browse files
lancepiochDaneEveritt
authored andcommitted
Replace magic numbers with constants (pterodactyl#754)
* Replace magic numbers with constants
1 parent 6043114 commit f94e4c1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class CleanServiceBackupFilesCommand extends Command
1717
{
18+
const BACKUP_THRESHOLD_MINUTES = 5;
19+
1820
/**
1921
* @var \Carbon\Carbon
2022
*/
@@ -58,7 +60,7 @@ public function handle()
5860

5961
collect($files)->each(function ($file) {
6062
$lastModified = $this->carbon->timestamp($this->disk->lastModified($file));
61-
if ($lastModified->diffInMinutes($this->carbon->now()) > 5) {
63+
if ($lastModified->diffInMinutes($this->carbon->now()) > self::BACKUP_THRESHOLD_MINUTES) {
6264
$this->disk->delete($file);
6365
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file]));
6466
}

app/Repositories/Eloquent/NodeRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
1818
{
1919
use Searchable;
2020

21+
const THRESHOLD_PERCENTAGE_LOW = 75;
22+
const THRESHOLD_PERCENTAGE_MEDIUM = 90;
23+
2124
/**
2225
* {@inheritdoc}
2326
*/
@@ -56,7 +59,7 @@ public function getUsageStats($id)
5659
'value' => number_format($value),
5760
'max' => number_format($maxUsage),
5861
'percent' => $percent,
59-
'css' => ($percent <= 75) ? 'green' : (($percent > 90) ? 'red' : 'yellow'),
62+
'css' => ($percent <= self::THRESHOLD_PERCENTAGE_LOW) ? 'green' : (($percent > self::THRESHOLD_PERCENTAGE_MEDIUM) ? 'red' : 'yellow'),
6063
],
6164
];
6265
})

app/Services/Schedules/Tasks/TaskCreationService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
class TaskCreationService
1818
{
19+
const MAX_INTERVAL_TIME_SECONDS = 900;
20+
1921
/**
2022
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
2123
*/
@@ -50,7 +52,7 @@ public function handle($schedule, array $data, $returnModel = true)
5052

5153
$schedule = ($schedule instanceof Schedule) ? $schedule->id : $schedule;
5254
$delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value'];
53-
if ($delay > 900) {
55+
if ($delay > self::MAX_INTERVAL_TIME_SECONDS) {
5456
throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long'));
5557
}
5658

0 commit comments

Comments
 (0)