upgrade to laravel 8.x

This commit is contained in:
2021-05-30 08:20:41 +00:00
parent 41b78a0599
commit 3ad6ed8bfa
2333 changed files with 113904 additions and 59058 deletions
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Cron;
use DateTime;
@@ -7,7 +9,7 @@ use DateTimeInterface;
use InvalidArgumentException;
/**
* Day of week field. Allows: * / , - ? L #
* Day of week field. Allows: * / , - ? L #.
*
* Days of the week can be represented as a number 0-7 (0|7 = Sunday)
* or as a three letter string: SUN, MON, TUE, WED, THU, FRI, SAT.
@@ -22,12 +24,12 @@ use InvalidArgumentException;
class DayOfWeekField extends AbstractField
{
/**
* @inheritDoc
* {@inheritdoc}
*/
protected $rangeStart = 0;
/**
* @inheritDoc
* {@inheritdoc}
*/
protected $rangeEnd = 7;
@@ -37,7 +39,7 @@ class DayOfWeekField extends AbstractField
protected $nthRange;
/**
* @inheritDoc
* {@inheritdoc}
*/
protected $literals = [1 => 'MON', 2 => 'TUE', 3 => 'WED', 4 => 'THU', 5 => 'FRI', 6 => 'SAT', 7 => 'SUN'];
@@ -55,39 +57,39 @@ class DayOfWeekField extends AbstractField
*
* @param \DateTime|\DateTimeImmutable $date
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
public function isSatisfiedBy(DateTimeInterface $date, $value): bool
{
if ($value == '?') {
if ('?' === $value) {
return true;
}
// Convert text day of the week values to integers
$value = $this->convertLiterals($value);
$currentYear = $date->format('Y');
$currentMonth = $date->format('m');
$lastDayOfMonth = $date->format('t');
$currentYear = (int) $date->format('Y');
$currentMonth = (int) $date->format('m');
$lastDayOfMonth = (int) $date->format('t');
// Find out if this is the last specific weekday of the month
if (strpos($value, 'L')) {
$weekday = (int) $this->convertLiterals(substr($value, 0, strpos($value, 'L')));
/** @phpstan-ignore-next-line */
$weekday = $this->convertLiterals(substr($value, 0, strpos($value, 'L')));
$weekday %= 7;
$tdate = clone $date;
$tdate = $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
while ($tdate->format('w') != $weekday) {
$tdateClone = new DateTime();
$tdate = $tdateClone
->setTimezone($tdate->getTimezone())
$tdate = $tdateClone->setTimezone($tdate->getTimezone())
->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
}
return $date->format('j') == $lastDayOfMonth;
return (int) $date->format('j') === $lastDayOfMonth;
}
// Handle # hash tokens
if (strpos($value, '#')) {
list($weekday, $nth) = explode('#', $value);
[$weekday, $nth] = explode('#', $value);
if (!is_numeric($nth)) {
throw new InvalidArgumentException("Hashed weekdays must be numeric, {$nth} given");
@@ -96,23 +98,23 @@ class DayOfWeekField extends AbstractField
}
// 0 and 7 are both Sunday, however 7 matches date('N') format ISO-8601
if ($weekday === '0') {
if ('0' === $weekday) {
$weekday = 7;
}
$weekday = $this->convertLiterals($weekday);
$weekday = (int) $this->convertLiterals((string) $weekday);
// Validate the hash fields
if ($weekday < 0 || $weekday > 7) {
throw new InvalidArgumentException("Weekday must be a value between 0 and 7. {$weekday} given");
}
if (!in_array($nth, $this->nthRange)) {
if (!\in_array($nth, $this->nthRange, true)) {
throw new InvalidArgumentException("There are never more than 5 or less than 1 of a given weekday in a month, {$nth} given");
}
// The current weekday must match the targeted weekday to proceed
if ($date->format('N') != $weekday) {
if ((int) $date->format('N') !== $weekday) {
return false;
}
@@ -121,7 +123,7 @@ class DayOfWeekField extends AbstractField
$dayCount = 0;
$currentDay = 1;
while ($currentDay < $lastDayOfMonth + 1) {
if ($tdate->format('N') == $weekday) {
if ((int) $tdate->format('N') === $weekday) {
if (++$dayCount >= $nth) {
break;
}
@@ -129,23 +131,25 @@ class DayOfWeekField extends AbstractField
$tdate = $tdate->setDate($currentYear, $currentMonth, ++$currentDay);
}
return $date->format('j') == $currentDay;
return (int) $date->format('j') === $currentDay;
}
// Handle day of the week values
if (strpos($value, '-')) {
if (false !== strpos($value, '-')) {
$parts = explode('-', $value);
if ($parts[0] == '7') {
$parts[0] = '0';
} elseif ($parts[1] == '0') {
$parts[1] = '7';
if ('7' === $parts[0]) {
$parts[0] = 0;
} elseif ('0' === $parts[1]) {
$parts[1] = 7;
}
$value = implode('-', $parts);
}
// Test to see which Sunday to use -- 0 == 7 == Sunday
$format = in_array(7, str_split($value)) ? 'N' : 'w';
$fieldValue = $date->format($format);
$format = \in_array(7, array_map(function ($value) {
return (int) $value;
}, str_split($value)), true) ? 'N' : 'w';
$fieldValue = (int) $date->format($format);
return $this->isSatisfied($fieldValue, $value);
}
@@ -153,9 +157,9 @@ class DayOfWeekField extends AbstractField
/**
* @inheritDoc
*
* @param \DateTime|\DateTimeImmutable &$date
* @param \DateTime|\DateTimeImmutable $date
*/
public function increment(DateTimeInterface &$date, $invert = false)
public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface
{
if ($invert) {
$date = $date->modify('-1 day')->setTime(23, 59, 0);
@@ -167,19 +171,23 @@ class DayOfWeekField extends AbstractField
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public function validate($value)
public function validate(string $value): bool
{
$basicChecks = parent::validate($value);
if (!$basicChecks) {
if ('?' === $value) {
return true;
}
// Handle the # value
if (strpos($value, '#') !== false) {
if (false !== strpos($value, '#')) {
$chunks = explode('#', $value);
$chunks[0] = $this->convertLiterals($chunks[0]);
if (parent::validate($chunks[0]) && is_numeric($chunks[1]) && in_array($chunks[1], $this->nthRange)) {
if (parent::validate($chunks[0]) && is_numeric($chunks[1]) && \in_array((int) $chunks[1], $this->nthRange, true)) {
return true;
}
}