instances added god may help

This commit is contained in:
2026-02-23 12:58:19 +01:00
parent 25370a1a55
commit 99db252f60
290 changed files with 9858 additions and 4914 deletions

View File

@@ -4,7 +4,7 @@ namespace MintyPHP\Service\Scheduler;
class ScheduleCalculator
{
public static function normalizeTimezone(?string $timezone): string
public function normalizeTimezone(?string $timezone): string
{
$timezone = trim((string) $timezone);
if ($timezone === '') {
@@ -18,15 +18,15 @@ class ScheduleCalculator
}
}
public static function normalizeScheduleType(?string $type): string
public function normalizeScheduleType(?string $type): string
{
$type = strtolower(trim((string) $type));
return in_array($type, ['hourly', 'daily', 'weekly'], true) ? $type : 'daily';
}
public static function normalizeInterval(string $type, int $value): int
public function normalizeInterval(string $type, int $value): int
{
$type = self::normalizeScheduleType($type);
$type = $this->normalizeScheduleType($type);
if ($type === 'hourly') {
return max(1, min(24, $value));
}
@@ -36,7 +36,7 @@ class ScheduleCalculator
return max(1, min(365, $value));
}
public static function normalizeTime(?string $time): ?string
public function normalizeTime(?string $time): ?string
{
$time = trim((string) $time);
if ($time === '') {
@@ -53,9 +53,9 @@ class ScheduleCalculator
return sprintf('%02d:%02d', $hour, $minute);
}
public static function normalizeWeekdaysCsv(mixed $value): ?string
public function normalizeWeekdaysCsv(mixed $value): ?string
{
$list = self::parseWeekdays($value);
$list = $this->parseWeekdays($value);
if (!$list) {
return null;
}
@@ -65,7 +65,7 @@ class ScheduleCalculator
/**
* @return array<int>
*/
public static function parseWeekdays(mixed $value): array
public function parseWeekdays(mixed $value): array
{
$raw = [];
if (is_array($value)) {
@@ -104,12 +104,12 @@ class ScheduleCalculator
* Returns null if the schedule is misconfigured (e.g. missing schedule_time for daily/weekly)
* or if no valid next run could be found within the search window.
*/
public static function calculateNextRunUtc(array $job, ?\DateTimeImmutable $referenceUtc = null): ?\DateTimeImmutable
public function calculateNextRunUtc(array $job, ?\DateTimeImmutable $referenceUtc = null): ?\DateTimeImmutable
{
$referenceUtc = $referenceUtc ?? new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
$type = self::normalizeScheduleType((string) ($job['schedule_type'] ?? 'daily'));
$interval = self::normalizeInterval($type, (int) ($job['schedule_interval'] ?? 1));
$timezone = new \DateTimeZone(self::normalizeTimezone((string) ($job['timezone'] ?? '')));
$type = $this->normalizeScheduleType((string) ($job['schedule_type'] ?? 'daily'));
$interval = $this->normalizeInterval($type, (int) ($job['schedule_interval'] ?? 1));
$timezone = new \DateTimeZone($this->normalizeTimezone((string) ($job['timezone'] ?? '')));
$localReference = $referenceUtc->setTimezone($timezone);
if ($type === 'hourly') {
@@ -120,7 +120,7 @@ class ScheduleCalculator
return $candidate->setTimezone(new \DateTimeZone('UTC'));
}
$time = self::normalizeTime((string) ($job['schedule_time'] ?? ''));
$time = $this->normalizeTime((string) ($job['schedule_time'] ?? ''));
if ($time === null) {
return null;
}
@@ -138,7 +138,7 @@ class ScheduleCalculator
// week interval. The search window is 1110 days (~3 years), which comfortably covers
// the maximum weekly interval of 52 weeks × 7 days/week = 364 days, with margin for
// weekday alignment and DST edge cases.
$weekdays = self::parseWeekdays((string) ($job['schedule_weekdays_csv'] ?? ''));
$weekdays = $this->parseWeekdays((string) ($job['schedule_weekdays_csv'] ?? ''));
if (!$weekdays) {
$weekdays = [1];
}