Skip to content

Commit

Permalink
Merge pull request #13 from thecaliskan/2.x
Browse files Browse the repository at this point in the history
Added PHP 8.4 support and fixed CS for 2.x
  • Loading branch information
kylekatarnls authored Jan 8, 2025
2 parents 1e9d506 + 142f0f5 commit 9228ce9
Show file tree
Hide file tree
Showing 35 changed files with 72 additions and 51 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ jobs:
- php: 8.3
setup: lowest

- php: 8.4

- php: 8.1
laravel: true
reference: 10.x
Expand All @@ -87,6 +89,14 @@ jobs:
laravel: true
reference: master

- php: 8.3
laravel: true
reference: master

- php: 8.4
laravel: true
reference: master

- php: 8.2
laravel: true
reference: master
Expand Down Expand Up @@ -148,7 +158,7 @@ jobs:
if [[ "${{ matrix.laravel }}" != 'true' ]]; then
composer remove --no-update kylekatarnls/multi-tester --no-interaction --dev;
fi;
${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^9.5.20 --no-interaction --dev;' || '' }}
${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^9.6.21 --no-interaction --dev;' || '' }}
composer update --prefer-dist --no-progress --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.classmap-authoritative && '--classmap-authoritative' || '' }}${{ matrix.php >= 8.2 && ' --ignore-platform-reqs' || '' }};
- name: Run test suite
Expand Down Expand Up @@ -230,6 +240,8 @@ jobs:
- php: 8.3
setup: lowest

- php: 8.4

name: PHP ${{ matrix.php }} - ${{ matrix.setup || 'stable' }} - windows

steps:
Expand Down Expand Up @@ -263,7 +275,7 @@ jobs:
max_attempts: 3
command: |
composer remove --no-update kylekatarnls/multi-tester phpmd/phpmd friendsofphp/php-cs-fixer --no-interaction --dev;
${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^9.5.20 --no-interaction --dev;' || '' }}
${{ matrix.php >= 8.1 && 'composer require --no-update phpunit/phpunit:^9.6.21 --no-interaction --dev;' || '' }}
composer update --prefer-dist --no-progress --prefer-${{ matrix.setup || 'stable' }}${{ matrix.php >= 8.2 && ' --ignore-platform-reqs' || '' }};
- name: Run test suite
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'statement_indentation' => false,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/AbstractTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function get($locale = null)
return static::$singletons[$key];
}

public function __construct($locale, MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false)
public function __construct($locale, ?MessageFormatterInterface $formatter = null, $cacheDir = null, $debug = false)
{
parent::setLocale($locale);
$this->initializing = true;
Expand Down Expand Up @@ -162,7 +162,7 @@ public function resetMessages($locale = null)
$this->assertValidLocale($locale);

foreach ($this->getDirectories() as $directory) {
$data = @include sprintf('%s/%s.php', rtrim($directory, '\\/'), $locale);
$data = @include \sprintf('%s/%s.php', rtrim($directory, '\\/'), $locale);

if ($data !== false) {
$this->messages[$locale] = $data;
Expand Down
1 change: 1 addition & 0 deletions src/Carbon/CarbonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ public static function createFromTimeString($time, $tz = null);
*
* @return static
*/
#[ReturnTypeWillChange]
public static function createFromTimestamp($timestamp, $tz = null);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/CarbonInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public static function fromString($intervalDefinition)

default:
throw new InvalidIntervalException(
sprintf('Invalid part %s in definition %s', $part, $intervalDefinition)
\sprintf('Invalid part %s in definition %s', $part, $intervalDefinition)
);
}
}
Expand Down Expand Up @@ -2329,7 +2329,7 @@ public static function getDateIntervalSpec(DateInterval $interval, bool $microse

$seconds = abs($interval->s);
if ($microseconds && $interval->f > 0) {
$seconds = sprintf('%d.%06d', $seconds, abs($interval->f) * 1000000);
$seconds = \sprintf('%d.%06d', $seconds, abs($interval->f) * 1000000);
}

$time = array_filter([
Expand Down
6 changes: 3 additions & 3 deletions src/Carbon/CarbonPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ public function getDateInterval()
*
* @return CarbonInterface
*/
public function getStartDate(string $rounding = null)
public function getStartDate(?string $rounding = null)
{
$date = $this->startDate->avoidMutation();

Expand All @@ -1031,7 +1031,7 @@ public function getStartDate(string $rounding = null)
*
* @return CarbonInterface|null
*/
public function getEndDate(string $rounding = null)
public function getEndDate(?string $rounding = null)
{
if (!$this->endDate) {
return null;
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public function shiftTimezone($timezone)
*
* @return CarbonInterface
*/
public function calculateEnd(string $rounding = null)
public function calculateEnd(?string $rounding = null)
{
if ($end = $this->getEndDate($rounding)) {
return $end;
Expand Down
8 changes: 4 additions & 4 deletions src/Carbon/CarbonTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function getAbbr($dst = false)
*
* @return string
*/
public function toOffsetName(DateTimeInterface $date = null)
public function toOffsetName(?DateTimeInterface $date = null)
{
return static::getOffsetNameFromMinuteOffset(
$this->getOffset($date ?: Carbon::now($this)) / 60
Expand All @@ -169,7 +169,7 @@ public function toOffsetName(DateTimeInterface $date = null)
*
* @return CarbonTimeZone
*/
public function toOffsetTimeZone(DateTimeInterface $date = null)
public function toOffsetTimeZone(?DateTimeInterface $date = null)
{
return new static($this->toOffsetName($date));
}
Expand All @@ -185,7 +185,7 @@ public function toOffsetTimeZone(DateTimeInterface $date = null)
*
* @return string|false
*/
public function toRegionName(DateTimeInterface $date = null, $isDst = 1)
public function toRegionName(?DateTimeInterface $date = null, $isDst = 1)
{
$name = $this->getName();
$firstChar = substr($name, 0, 1);
Expand Down Expand Up @@ -227,7 +227,7 @@ public function toRegionName(DateTimeInterface $date = null, $isDst = 1)
*
* @return CarbonTimeZone|false
*/
public function toRegionTimeZone(DateTimeInterface $date = null)
public function toRegionTimeZone(?DateTimeInterface $date = null)
{
$tz = $this->toRegionName($date);

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/BadComparisonUnitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BadComparisonUnitException extends UnitException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($unit, $code = 0, Throwable $previous = null)
public function __construct($unit, $code = 0, ?Throwable $previous = null)
{
$this->unit = $unit;

Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Exceptions/BadFluentConstructorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class BadFluentConstructorException extends BaseBadMethodCallException implement
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($method, $code = 0, Throwable $previous = null)
public function __construct($method, $code = 0, ?Throwable $previous = null)
{
$this->method = $method;

parent::__construct(sprintf("Unknown fluent constructor '%s'.", $method), $code, $previous);
parent::__construct(\sprintf("Unknown fluent constructor '%s'.", $method), $code, $previous);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Exceptions/BadFluentSetterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class BadFluentSetterException extends BaseBadMethodCallException implements Bad
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($setter, $code = 0, Throwable $previous = null)
public function __construct($setter, $code = 0, ?Throwable $previous = null)
{
$this->setter = $setter;

parent::__construct(sprintf("Unknown fluent setter '%s'", $setter), $code, $previous);
parent::__construct(\sprintf("Unknown fluent setter '%s'", $setter), $code, $previous);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/ImmutableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ImmutableException extends BaseRuntimeException implements RuntimeExceptio
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($value, $code = 0, Throwable $previous = null)
public function __construct($value, $code = 0, ?Throwable $previous = null)
{
$this->value = $value;
parent::__construct("$value is immutable.", $code, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/InvalidDateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class InvalidDateException extends BaseInvalidArgumentException implements Inval
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($field, $value, $code = 0, Throwable $previous = null)
public function __construct($field, $value, $code = 0, ?Throwable $previous = null)
{
$this->field = $field;
$this->value = $value;
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Exceptions/NotACarbonClassException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class NotACarbonClassException extends BaseInvalidArgumentException implements I
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($className, $code = 0, Throwable $previous = null)
public function __construct($className, $code = 0, ?Throwable $previous = null)
{
$this->className = $className;

parent::__construct(sprintf('Given class does not implement %s: %s', CarbonInterface::class, $className), $code, $previous);
parent::__construct(\sprintf('Given class does not implement %s: %s', CarbonInterface::class, $className), $code, $previous);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/NotLocaleAwareException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NotLocaleAwareException extends BaseInvalidArgumentException implements In
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($object, $code = 0, Throwable $previous = null)
public function __construct($object, $code = 0, ?Throwable $previous = null)
{
$dump = \is_object($object) ? \get_class($object) : \gettype($object);

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/OutOfRangeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class OutOfRangeException extends BaseInvalidArgumentException implements Invali
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($unit, $min, $max, $value, $code = 0, Throwable $previous = null)
public function __construct($unit, $min, $max, $value, $code = 0, ?Throwable $previous = null)
{
$this->unit = $unit;
$this->min = $min;
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/ParseErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ParseErrorException extends BaseInvalidArgumentException implements Invali
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($expected, $actual, $help = '', $code = 0, Throwable $previous = null)
public function __construct($expected, $actual, $help = '', $code = 0, ?Throwable $previous = null)
{
$this->expected = $expected;
$this->actual = $actual;
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/UnitNotConfiguredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UnitNotConfiguredException extends UnitException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($unit, $code = 0, Throwable $previous = null)
public function __construct($unit, $code = 0, ?Throwable $previous = null)
{
$this->unit = $unit;

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/UnknownGetterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnknownGetterException extends BaseInvalidArgumentException implements Inv
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($getter, $code = 0, Throwable $previous = null)
public function __construct($getter, $code = 0, ?Throwable $previous = null)
{
$this->getter = $getter;

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/UnknownMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnknownMethodException extends BaseBadMethodCallException implements BadMe
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($method, $code = 0, Throwable $previous = null)
public function __construct($method, $code = 0, ?Throwable $previous = null)
{
$this->method = $method;

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/UnknownSetterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnknownSetterException extends BaseInvalidArgumentException implements Bad
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($setter, $code = 0, Throwable $previous = null)
public function __construct($setter, $code = 0, ?Throwable $previous = null)
{
$this->setter = $setter;

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Exceptions/UnknownUnitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UnknownUnitException extends UnitException
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($unit, $code = 0, Throwable $previous = null)
public function __construct($unit, $code = 0, ?Throwable $previous = null)
{
$this->unit = $unit;

Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function setClassName(string $className)
return $this;
}

public function className(string $className = null)
public function className(?string $className = null)
{
return $className === null ? $this->getClassName() : $this->setClassName($className);
}
Expand All @@ -283,7 +283,7 @@ public function setSettings(array $settings)
return $this;
}

public function settings(array $settings = null)
public function settings(?array $settings = null)
{
return $settings === null ? $this->getSettings() : $this->setSettings($settings);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public static function create($year = 0, $month = 1, $day = 1, $hour = 0, $minut
}

$second = ($second < 10 ? '0' : '').number_format($second, 6);
$instance = static::rawCreateFromFormat('!Y-n-j G:i:s.u', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz);
$instance = static::rawCreateFromFormat('!Y-n-j G:i:s.u', \sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz);

if ($fixYear !== null) {
$instance = $instance->addYears($fixYear);
Expand Down
12 changes: 6 additions & 6 deletions src/Carbon/Traits/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public function get($name)
return $this->hour ?: 24;
// @property int
case $name === 'milliseconds':
// @property int
// @property int
case $name === 'millisecond':
// @property int
case $name === 'milli':
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public function __set($name, $value)
public function set($name, $value = null)
{
if ($this->isImmutable()) {
throw new ImmutableException(sprintf('%s class', static::class));
throw new ImmutableException(\sprintf('%s class', static::class));
}

if (\is_array($name)) {
Expand Down Expand Up @@ -1391,7 +1391,7 @@ public function isoWeekday($value = null)
*
* @return int
*/
public function getDaysFromStartOfWeek(int $weekStartsAt = null): int
public function getDaysFromStartOfWeek(?int $weekStartsAt = null): int
{
$firstDay = (int) ($weekStartsAt ?? $this->getTranslationMessage('first_day_of_week') ?? 0);

Expand All @@ -1409,7 +1409,7 @@ public function getDaysFromStartOfWeek(int $weekStartsAt = null): int
*
* @return static
*/
public function setDaysFromStartOfWeek(int $numberOfDays, int $weekStartsAt = null)
public function setDaysFromStartOfWeek(int $numberOfDays, ?int $weekStartsAt = null)
{
return $this->addDays($numberOfDays - $this->getDaysFromStartOfWeek($weekStartsAt));
}
Expand Down Expand Up @@ -1478,7 +1478,7 @@ public function subUnitNoOverflow($valueUnit, $value, $overflowUnit)
*
* @return int|static
*/
public function utcOffset(int $minuteOffset = null)
public function utcOffset(?int $minuteOffset = null)
{
if (\func_num_args() < 1) {
return $this->offsetMinutes;
Expand Down Expand Up @@ -2453,7 +2453,7 @@ public static function __callStatic($method, $parameters)
}
}
if (static::isStrictModeEnabled()) {
throw new UnknownMethodException(sprintf('%s::%s', static::class, $method));
throw new UnknownMethodException(\sprintf('%s::%s', static::class, $method));
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public function translateTimeStringTo($timeString, $to = null)
*
* @return $this|string
*/
public function locale(string $locale = null, ...$fallbackLocales)
public function locale(?string $locale = null, ...$fallbackLocales)
{
if ($locale === null) {
return $this->getTranslatorLocale();
Expand Down
Loading

0 comments on commit 9228ce9

Please sign in to comment.