upgrade to laravel 7 and set branch to v2

This commit is contained in:
2020-12-25 11:22:15 +00:00
parent 516105c492
commit 0ddd298350
4638 changed files with 132501 additions and 190226 deletions
+112 -76
View File
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -12,6 +14,7 @@
*/
namespace Cake\Chronos;
use BadMethodCallException;
use DateInterval;
use InvalidArgumentException;
@@ -27,61 +30,61 @@ use InvalidArgumentException;
* @property int $hours Total hours of the current interval.
* @property int $minutes Total minutes of the current interval.
* @property int $seconds Total seconds of the current interval.
*
* @property int $microseconds Total microseconds of the current interval.
* @property-read int $dayzExcludeWeeks Total days remaining in the final week of the current instance (days % 7).
* @property-read int $daysExcludeWeeks alias of dayzExcludeWeeks
*
* @method static ChronosInterval years($years = 1) Create instance specifying a number of years.
* @method static ChronosInterval year($years = 1) Alias for years
* @method static ChronosInterval months($months = 1) Create instance specifying a number of months.
* @method static ChronosInterval month($months = 1) Alias for months
* @method static ChronosInterval weeks($weeks = 1) Create instance specifying a number of weeks.
* @method static ChronosInterval week($weeks = 1) Alias for weeks
* @method static ChronosInterval days($days = 1) Create instance specifying a number of days.
* @method static ChronosInterval dayz($days = 1) Alias for days
* @method static ChronosInterval day($days = 1) Alias for days
* @method static ChronosInterval hours($hours = 1) Create instance specifying a number of hours.
* @method static ChronosInterval hour($hours = 1) Alias for hours
* @method static ChronosInterval minutes($minutes = 1) Create instance specifying a number of minutes.
* @method static ChronosInterval minute($minutes = 1) Alias for minutes
* @method static ChronosInterval seconds($seconds = 1) Create instance specifying a number of seconds.
* @method static ChronosInterval second($seconds = 1) Alias for seconds
*
* @method ChronosInterval years() years($years = 1) Set the years portion of the current interval.
* @method ChronosInterval year() year($years = 1) Alias for years.
* @method ChronosInterval months() months($months = 1) Set the months portion of the current interval.
* @method ChronosInterval month() month($months = 1) Alias for months.
* @method ChronosInterval weeks() weeks($weeks = 1) Set the weeks portion of the current interval. Will overwrite dayz value.
* @method ChronosInterval week() week($weeks = 1) Alias for weeks.
* @method ChronosInterval days() days($days = 1) Set the days portion of the current interval.
* @method ChronosInterval dayz() dayz($days = 1) Alias for days.
* @method ChronosInterval day() day($days = 1) Alias for days.
* @method ChronosInterval hours() hours($hours = 1) Set the hours portion of the current interval.
* @method ChronosInterval hour() hour($hours = 1) Alias for hours.
* @method ChronosInterval minutes() minutes($minutes = 1) Set the minutes portion of the current interval.
* @method ChronosInterval minute() minute($minutes = 1) Alias for minutes.
* @method ChronosInterval seconds() seconds($seconds = 1) Set the seconds portion of the current interval.
* @method ChronosInterval second() second($seconds = 1) Alias for seconds.
* @method static \Cake\Chronos\ChronosInterval years($years = 1) Create instance specifying a number of years.
* @method static \Cake\Chronos\ChronosInterval year($years = 1) Alias for years
* @method static \Cake\Chronos\ChronosInterval months($months = 1) Create instance specifying a number of months.
* @method static \Cake\Chronos\ChronosInterval month($months = 1) Alias for months
* @method static \Cake\Chronos\ChronosInterval weeks($weeks = 1) Create instance specifying a number of weeks.
* @method static \Cake\Chronos\ChronosInterval week($weeks = 1) Alias for weeks
* @method static \Cake\Chronos\ChronosInterval days($days = 1) Create instance specifying a number of days.
* @method static \Cake\Chronos\ChronosInterval dayz($days = 1) Alias for days
* @method static \Cake\Chronos\ChronosInterval day($days = 1) Alias for days
* @method static \Cake\Chronos\ChronosInterval hours($hours = 1) Create instance specifying a number of hours.
* @method static \Cake\Chronos\ChronosInterval hour($hours = 1) Alias for hours
* @method static \Cake\Chronos\ChronosInterval minutes($minutes = 1) Create instance specifying a number of minutes.
* @method static \Cake\Chronos\ChronosInterval minute($minutes = 1) Alias for minutes
* @method static \Cake\Chronos\ChronosInterval seconds($seconds = 1) Create instance specifying a number of seconds.
* @method static \Cake\Chronos\ChronosInterval second($seconds = 1) Alias for seconds
* @method static \Cake\Chronos\ChronosInterval microseconds($microseconds = 1) Create instance specifying a number of microseconds.
* @method static \Cake\Chronos\ChronosInterval microsecond($microseconds = 1) Alias for microseconds
*/
class ChronosInterval extends DateInterval
{
/**
* Interval spec period designators
* @var string
*/
const PERIOD_PREFIX = 'P';
const PERIOD_YEARS = 'Y';
const PERIOD_MONTHS = 'M';
const PERIOD_DAYS = 'D';
const PERIOD_TIME_PREFIX = 'T';
const PERIOD_HOURS = 'H';
const PERIOD_MINUTES = 'M';
const PERIOD_SECONDS = 'S';
public const PERIOD_PREFIX = 'P';
/**
* Before PHP 5.4.20/5.5.4 instead of `false` days will be set to -99999 when the interval instance
* was created by DateTime:diff().
* @var string
*/
const PHP_DAYS_FALSE = -99999;
public const PERIOD_YEARS = 'Y';
/**
* @var string
*/
public const PERIOD_MONTHS = 'M';
/**
* @var string
*/
public const PERIOD_DAYS = 'D';
/**
* @var string
*/
public const PERIOD_TIME_PREFIX = 'T';
/**
* @var string
*/
public const PERIOD_HOURS = 'H';
/**
* @var string
*/
public const PERIOD_MINUTES = 'M';
/**
* @var string
*/
public const PERIOD_SECONDS = 'S';
/**
* Determine if the interval was created via DateTime:diff() or not.
@@ -89,9 +92,9 @@ class ChronosInterval extends DateInterval
* @param \DateInterval $interval The interval to check.
* @return bool
*/
protected static function wasCreatedFromDiff(DateInterval $interval)
protected static function wasCreatedFromDiff(DateInterval $interval): bool
{
return ($interval->days !== false && $interval->days !== static::PHP_DAYS_FALSE);
return $interval->days !== false;
}
/**
@@ -104,9 +107,18 @@ class ChronosInterval extends DateInterval
* @param int|null $hours The hours to use.
* @param int|null $minutes The minutes to use.
* @param int|null $seconds The seconds to use.
* @param int|null $microseconds The microseconds to use.
*/
public function __construct($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null)
{
public function __construct(
?int $years = 1,
?int $months = null,
?int $weeks = null,
?int $days = null,
?int $hours = null,
?int $minutes = null,
?int $seconds = null,
?int $microseconds = null
) {
$spec = static::PERIOD_PREFIX;
$spec .= $years > 0 ? $years . static::PERIOD_YEARS : '';
@@ -116,7 +128,7 @@ class ChronosInterval extends DateInterval
$specDays += $weeks > 0 ? $weeks * ChronosInterface::DAYS_PER_WEEK : 0;
$specDays += $days > 0 ? $days : 0;
$spec .= ($specDays > 0) ? $specDays . static::PERIOD_DAYS : '';
$spec .= $specDays > 0 ? $specDays . static::PERIOD_DAYS : '';
if ($spec === static::PERIOD_PREFIX) {
$spec .= '0' . static::PERIOD_YEARS;
@@ -130,6 +142,10 @@ class ChronosInterval extends DateInterval
}
parent::__construct($spec);
if ($microseconds > 0) {
$this->f = $microseconds / 1000000;
}
}
/**
@@ -145,11 +161,20 @@ class ChronosInterval extends DateInterval
* @param int|null $hours The hours to use.
* @param int|null $minutes The minutes to use.
* @param int|null $seconds The seconds to use.
* @param int|null $microseconds The microseconds to use.
* @return static
*/
public static function create($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null)
{
return new static($years, $months, $weeks, $days, $hours, $minutes, $seconds);
public static function create(
?int $years = 1,
?int $months = null,
?int $weeks = null,
?int $days = null,
?int $hours = null,
?int $minutes = null,
?int $seconds = null,
?int $microseconds = null
): self {
return new static($years, $months, $weeks, $days, $hours, $minutes, $seconds, $microseconds);
}
/**
@@ -168,7 +193,7 @@ class ChronosInterval extends DateInterval
* @param array $args Contains the value to use.
* @return static
*/
public static function __callStatic($name, $args)
public static function __callStatic(string $name, array $args): self
{
$arg = count($args) === 0 ? 1 : $args[0];
@@ -201,7 +226,13 @@ class ChronosInterval extends DateInterval
case 'seconds':
case 'second':
return new static(null, null, null, null, null, null, $arg);
case 'microseconds':
case 'microsecond':
return new static(null, null, null, null, null, null, null, $arg);
}
throw new BadMethodCallException(sprintf('Cannot create interval with `%s` units', $name));
}
/**
@@ -213,15 +244,16 @@ class ChronosInterval extends DateInterval
* @throws \InvalidArgumentException
* @return static
*/
public static function instance(DateInterval $di)
public static function instance(DateInterval $di): self
{
if (static::wasCreatedFromDiff($di)) {
throw new InvalidArgumentException(
"Can not instance a DateInterval object created from DateTime::diff()."
'Can not instance a DateInterval object created from DateTime::diff().'
);
}
$instance = new static($di->y, $di->m, 0, $di->d, $di->h, $di->i, $di->s);
$instance->f = $di->f;
$instance->invert = $di->invert;
$instance->days = $di->days;
@@ -235,7 +267,7 @@ class ChronosInterval extends DateInterval
* @throws \InvalidArgumentException
* @return int
*/
public function __get($name)
public function __get(string $name)
{
switch ($name) {
case 'years':
@@ -256,22 +288,16 @@ class ChronosInterval extends DateInterval
case 'seconds':
return $this->s;
case 'microseconds':
return (int)($this->f * 1000000);
case 'weeks':
return (int)floor($this->d / ChronosInterface::DAYS_PER_WEEK);
case 'daysExcludeWeeks':
case 'dayzExcludeWeeks':
return $this->dayz % ChronosInterface::DAYS_PER_WEEK;
case 'days':
return $this->days;
case 'y':
case 'm':
case 'd':
case 'h':
case 'i':
case 's':
case 'invert':
return parent::__get($name);
default:
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
}
@@ -285,7 +311,7 @@ class ChronosInterval extends DateInterval
* @return void
* @throws \InvalidArgumentException
*/
public function __set($name, $val)
public function __set(string $name, $val): void
{
switch ($name) {
case 'years':
@@ -317,6 +343,10 @@ class ChronosInterval extends DateInterval
$this->s = $val;
break;
case 'microseconds':
$this->f = $val / 1000000;
break;
case 'invert':
$this->invert = $val;
break;
@@ -328,9 +358,9 @@ class ChronosInterval extends DateInterval
*
* @param int $weeks Number of weeks to set
* @param int $days Number of days to set
* @return static
* @return $this
*/
public function weeksAndDays($weeks, $days)
public function weeksAndDays(int $weeks, int $days)
{
$this->dayz = ($weeks * ChronosInterface::DAYS_PER_WEEK) + $days;
@@ -346,9 +376,9 @@ class ChronosInterval extends DateInterval
* @param string $name The property name to augment. Accepts plural forms in addition
* to singular ones.
* @param array $args The value to set.
* @return static
* @return $this
*/
public function __call($name, $args)
public function __call(string $name, array $args)
{
$arg = count($args) === 0 ? 1 : $args[0];
@@ -388,6 +418,11 @@ class ChronosInterval extends DateInterval
case 'second':
$this->seconds = $arg;
break;
case 'microseconds':
case 'microsecond':
$this->microseconds = $arg;
break;
}
return $this;
@@ -397,11 +432,11 @@ class ChronosInterval extends DateInterval
* Add the passed interval to the current instance
*
* @param \DateInterval $interval The interval to add.
* @return static
* @return $this
*/
public function add(DateInterval $interval)
{
$sign = ($interval->invert === 1) ? -1 : 1;
$sign = $interval->invert === 1 ? -1 : 1;
if (static::wasCreatedFromDiff($interval)) {
$this->dayz = $this->dayz + ($interval->days * $sign);
@@ -412,6 +447,7 @@ class ChronosInterval extends DateInterval
$this->hours = $this->hours + ($interval->h * $sign);
$this->minutes = $this->minutes + ($interval->i * $sign);
$this->seconds = $this->seconds + ($interval->s * $sign);
$this->microseconds = $this->microseconds + (int)($interval->f * 1000000 * $sign);
}
return $this;
@@ -422,7 +458,7 @@ class ChronosInterval extends DateInterval
*
* @return string Interval as string representation
*/
public function __toString()
public function __toString(): string
{
// equivalence
$oneMinuteInSeconds = 60;