Skip to content

Commit

Permalink
Upgrade to PHP 8.1 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored Dec 3, 2021
1 parent 8977917 commit 5b54dc1
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 90 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jobs:
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
ini-values: memory_limit=-1
coverage: none
tools: composer:v2

- name: 'Install Dependencies'
run: composer install --prefer-dist --no-progress --no-interaction
Expand All @@ -41,7 +49,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
ini-values: memory_limit=-1
coverage: none
tools: composer:v2
Expand All @@ -66,7 +74,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
ini-values: memory_limit=-1
coverage: none
tools: composer:v2
Expand All @@ -86,9 +94,7 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
steps:
- name: 'Checkout Code'
uses: actions/checkout@v2
Expand Down Expand Up @@ -121,7 +127,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
ini-values: memory_limit=-1
coverage: pcov
tools: composer:v2
Expand Down
2 changes: 2 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
preset: recommended

version: 8.1

enabled:
- combine_consecutive_unsets
- linebreak_after_opening_tag
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Requirements

* PHP 7.3, 7.4, 8.0
* PHP 8.1

## Installation 🌱

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
"issues": "https://github.com/fre5h/datetime-php/issues"
},
"require": {
"php": ">=7.3.0"
"php": ">=8.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"friendsofphp/php-cs-fixer": "^3.3",
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9.5",
"slam/phpstan-extensions": "^5.0",
"squizlabs/php_codesniffer": "^3.5",
"thecodingmachine/phpstan-strict-rules": "^0.12"
"slam/phpstan-extensions": "^6.0",
"squizlabs/php_codesniffer": "^3.6",
"thecodingmachine/phpstan-strict-rules": "^1.0.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ includes:
- 'vendor/phpstan/phpstan-phpunit/rules.neon'
- 'vendor/slam/phpstan-extensions/conf/slam-rules.neon'
parameters:
level: 8
excludes_analyse:
level: 9
excludePaths:
- '%rootDir%/../../../tests/*'
- '%rootDir%/../../../vendor/*'
fileExtensions:
Expand Down
6 changes: 2 additions & 4 deletions src/DateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ final class DateRange implements DateRangeInterface
{
private const INTERNAL_DATE_FORMAT = 'Y-m-d';

/** @var \DateTimeImmutable */
private $since;
private readonly \DateTimeImmutable $since;

/** @var \DateTimeImmutable */
private $till;
private readonly \DateTimeImmutable $till;

/**
* @param \DateTimeInterface $since
Expand Down
6 changes: 4 additions & 2 deletions src/DateTimeCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class DateTimeCloner
*/
public static function cloneIntoDateTime(\DateTimeInterface $originalDate): \DateTime
{
$timezone = $originalDate->getTimezone();
$date = \DateTime::createFromFormat(
self::DATE_FORMAT_FOR_CLONE,
$originalDate->format(self::DATE_FORMAT_FOR_CLONE),
$originalDate->getTimezone()
$timezone instanceof \DateTimeZone ? $timezone : null
);

if (!$date instanceof \DateTime) {
Expand All @@ -54,10 +55,11 @@ public static function cloneIntoDateTime(\DateTimeInterface $originalDate): \Dat
*/
public static function cloneIntoDateTimeImmutable(\DateTimeInterface $originalDate): \DateTimeImmutable
{
$timezone = $originalDate->getTimezone();
$date = \DateTimeImmutable::createFromFormat(
self::DATE_FORMAT_FOR_CLONE,
$originalDate->format(self::DATE_FORMAT_FOR_CLONE),
$originalDate->getTimezone()
$timezone instanceof \DateTimeZone ? $timezone : null
);

if (!$date instanceof \DateTimeImmutable) {
Expand Down
8 changes: 4 additions & 4 deletions src/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ class DateTimeHelper implements DateTimeHelperInterface
{
private const INTERNAL_DATE_FORMAT = 'Y-m-d';

/** @var mixed[] */
private $datesCache = [];
/** @var array<string, \DateTimeInterface[]> */
private array $datesCache = [];

/** @var \DateTimeZone|null */
private $timeZoneUtc;
private ?\DateTimeZone $timeZoneUtc = null;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -104,6 +103,7 @@ public function getDatesFromDateRangeAsArrayOfObjects(DateRangeInterface $dateRa
$datesAsObjects = [];
$period = new \DatePeriod($since, new \DateInterval('P1D'), $till);
foreach ($period as $date) {
/** @var \DateTimeInterface $date */
$datesAsObjects[] = $date;
}

Expand Down
6 changes: 2 additions & 4 deletions src/DateTimeRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
*/
final class DateTimeRange implements DateTimeRangeInterface
{
/** @var \DateTimeImmutable */
private $since;
private readonly \DateTimeImmutable $since;

/** @var \DateTimeImmutable */
private $till;
private readonly \DateTimeImmutable $till;

/**
* @param \DateTimeInterface $since
Expand Down
112 changes: 56 additions & 56 deletions src/TimeConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,64 @@
*/
final class TimeConstants
{
public const NUMBER_OF_MILLISECONDS_IN_A_SECOND = 1000;
public const NUMBER_OF_SECONDS_IN_A_MINUTE = 60;
public const NUMBER_OF_MINUTES_IN_AN_HOUR = 60;
public const NUMBER_OF_SECONDS_IN_AN_HOUR = self::NUMBER_OF_SECONDS_IN_A_MINUTE * self::NUMBER_OF_MINUTES_IN_AN_HOUR;
public const NUMBER_OF_HOURS_IN_A_DAY = 24;
public const NUMBER_OF_SECONDS_IN_A_DAY = self::NUMBER_OF_HOURS_IN_A_DAY * self::NUMBER_OF_SECONDS_IN_AN_HOUR;
final public const NUMBER_OF_MILLISECONDS_IN_A_SECOND = 1000;
final public const NUMBER_OF_SECONDS_IN_A_MINUTE = 60;
final public const NUMBER_OF_MINUTES_IN_AN_HOUR = 60;
final public const NUMBER_OF_SECONDS_IN_AN_HOUR = self::NUMBER_OF_SECONDS_IN_A_MINUTE * self::NUMBER_OF_MINUTES_IN_AN_HOUR;
final public const NUMBER_OF_HOURS_IN_A_DAY = 24;
final public const NUMBER_OF_SECONDS_IN_A_DAY = self::NUMBER_OF_HOURS_IN_A_DAY * self::NUMBER_OF_SECONDS_IN_AN_HOUR;

public const NUMBER_OF_DAYS_IN_A_WEEK = 7;
public const NUMBER_OF_MONTHS_IN_A_YEAR = 12;
public const NUMBER_OF_DAYS_IN_A_YEAR = 365;
public const NUMBER_OF_DAYS_IN_A_LEAP_YEAR = 366;
final public const NUMBER_OF_DAYS_IN_A_WEEK = 7;
final public const NUMBER_OF_MONTHS_IN_A_YEAR = 12;
final public const NUMBER_OF_DAYS_IN_A_YEAR = 365;
final public const NUMBER_OF_DAYS_IN_A_LEAP_YEAR = 366;

public const DAY_MONDAY = 'monday';
public const DAY_MONDAY_SHORT = 'mon';
public const DAY_TUESDAY = 'tuesday';
public const DAY_TUESDAY_SHORT = 'tue';
public const DAY_WEDNESDAY = 'wednesday';
public const DAY_WEDNESDAY_SHORT = 'wed';
public const DAY_THURSDAY = 'thursday';
public const DAY_THURSDAY_SHORT = 'thu';
public const DAY_FRIDAY = 'friday';
public const DAY_FRIDAY_SHORT = 'fri';
public const DAY_SATURDAY = 'saturday';
public const DAY_SATURDAY_SHORT = 'sat';
public const DAY_SUNDAY = 'sunday';
public const DAY_SUNDAY_SHORT = 'sun';
final public const DAY_MONDAY = 'monday';
final public const DAY_MONDAY_SHORT = 'mon';
final public const DAY_TUESDAY = 'tuesday';
final public const DAY_TUESDAY_SHORT = 'tue';
final public const DAY_WEDNESDAY = 'wednesday';
final public const DAY_WEDNESDAY_SHORT = 'wed';
final public const DAY_THURSDAY = 'thursday';
final public const DAY_THURSDAY_SHORT = 'thu';
final public const DAY_FRIDAY = 'friday';
final public const DAY_FRIDAY_SHORT = 'fri';
final public const DAY_SATURDAY = 'saturday';
final public const DAY_SATURDAY_SHORT = 'sat';
final public const DAY_SUNDAY = 'sunday';
final public const DAY_SUNDAY_SHORT = 'sun';

public const MONTH_JANUARY = 'january';
public const MONTH_JANUARY_SHORT = 'jan';
public const MONTH_FEBRUARY = 'february';
public const MONTH_FEBRUARY_SHORT = 'feb';
public const MONTH_MARCH = 'march';
public const MONTH_MARCH_SHORT = 'mar';
public const MONTH_APRIL = 'april';
public const MONTH_APRIL_SHORT = 'apr';
public const MONTH_MAY = 'may';
public const MONTH_MAY_SHORT = 'may';
public const MONTH_JUNE = 'june';
public const MONTH_JUNE_SHORT = 'jun';
public const MONTH_JULY = 'july';
public const MONTH_JULY_SHORT = 'jul';
public const MONTH_AUGUST = 'august';
public const MONTH_AUGUST_SHORT = 'aug';
public const MONTH_SEPTEMBER = 'september';
public const MONTH_SEPTEMBER_SHORT = 'sep';
public const MONTH_OCTOBER = 'october';
public const MONTH_OCTOBER_SHORT = 'oct';
public const MONTH_NOVEMBER = 'november';
public const MONTH_NOVEMBER_SHORT = 'nov';
public const MONTH_DECEMBER = 'december';
public const MONTH_DECEMBER_SHORT = 'dec';
final public const MONTH_JANUARY = 'january';
final public const MONTH_JANUARY_SHORT = 'jan';
final public const MONTH_FEBRUARY = 'february';
final public const MONTH_FEBRUARY_SHORT = 'feb';
final public const MONTH_MARCH = 'march';
final public const MONTH_MARCH_SHORT = 'mar';
final public const MONTH_APRIL = 'april';
final public const MONTH_APRIL_SHORT = 'apr';
final public const MONTH_MAY = 'may';
final public const MONTH_MAY_SHORT = 'may';
final public const MONTH_JUNE = 'june';
final public const MONTH_JUNE_SHORT = 'jun';
final public const MONTH_JULY = 'july';
final public const MONTH_JULY_SHORT = 'jul';
final public const MONTH_AUGUST = 'august';
final public const MONTH_AUGUST_SHORT = 'aug';
final public const MONTH_SEPTEMBER = 'september';
final public const MONTH_SEPTEMBER_SHORT = 'sep';
final public const MONTH_OCTOBER = 'october';
final public const MONTH_OCTOBER_SHORT = 'oct';
final public const MONTH_NOVEMBER = 'november';
final public const MONTH_NOVEMBER_SHORT = 'nov';
final public const MONTH_DECEMBER = 'december';
final public const MONTH_DECEMBER_SHORT = 'dec';

public const WINTER_MONTHS = [self::MONTH_DECEMBER, self::MONTH_JANUARY, self::MONTH_FEBRUARY];
public const WINTER_MONTHS_SHORT = [self::MONTH_DECEMBER_SHORT, self::MONTH_JANUARY_SHORT, self::MONTH_FEBRUARY_SHORT];
public const SPRING_MONTHS = [self::MONTH_MARCH, self::MONTH_APRIL, self::MONTH_MAY];
public const SPRING_MONTHS_SHORT = [self::MONTH_MARCH_SHORT, self::MONTH_APRIL_SHORT, self::MONTH_MAY_SHORT];
public const SUMMER_MONTHS = [self::MONTH_JUNE, self::MONTH_JULY, self::MONTH_AUGUST];
public const SUMMER_MONTHS_SHORT = [self::MONTH_JUNE_SHORT, self::MONTH_JULY_SHORT, self::MONTH_AUGUST_SHORT];
public const AUTUMN_MONTHS = [self::MONTH_SEPTEMBER, self::MONTH_OCTOBER, self::MONTH_NOVEMBER];
public const AUTUMN_MONTHS_SHORT = [self::MONTH_SEPTEMBER_SHORT, self::MONTH_OCTOBER_SHORT, self::MONTH_NOVEMBER_SHORT];
final public const WINTER_MONTHS = [self::MONTH_DECEMBER, self::MONTH_JANUARY, self::MONTH_FEBRUARY];
final public const WINTER_MONTHS_SHORT = [self::MONTH_DECEMBER_SHORT, self::MONTH_JANUARY_SHORT, self::MONTH_FEBRUARY_SHORT];
final public const SPRING_MONTHS = [self::MONTH_MARCH, self::MONTH_APRIL, self::MONTH_MAY];
final public const SPRING_MONTHS_SHORT = [self::MONTH_MARCH_SHORT, self::MONTH_APRIL_SHORT, self::MONTH_MAY_SHORT];
final public const SUMMER_MONTHS = [self::MONTH_JUNE, self::MONTH_JULY, self::MONTH_AUGUST];
final public const SUMMER_MONTHS_SHORT = [self::MONTH_JUNE_SHORT, self::MONTH_JULY_SHORT, self::MONTH_AUGUST_SHORT];
final public const AUTUMN_MONTHS = [self::MONTH_SEPTEMBER, self::MONTH_OCTOBER, self::MONTH_NOVEMBER];
final public const AUTUMN_MONTHS_SHORT = [self::MONTH_SEPTEMBER_SHORT, self::MONTH_OCTOBER_SHORT, self::MONTH_NOVEMBER_SHORT];
}
4 changes: 2 additions & 2 deletions tests/DateTimeClonerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testCloneIntoDateTimeWithException(): void
$datetime
->expects(self::once())
->method('getTimezone')
->willReturn(null)
->willReturn(false)
;

$this->expectException(UnexpectedValueException::class);
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testCloneIntoDateTimeImmutableWithException(): void
$datetime
->expects(self::once())
->method('getTimezone')
->willReturn(null)
->willReturn(false)
;

$this->expectException(UnexpectedValueException::class);
Expand Down
3 changes: 1 addition & 2 deletions tests/DateTimeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class DateTimeHelperTest extends TestCase
/** @var DateRangeInterface|MockObject */
private $dateRange;

/** @var DateTimeHelper */
private $dateTimeHelper;
private DateTimeHelper $dateTimeHelper;

protected function setUp(): void
{
Expand Down

0 comments on commit 5b54dc1

Please sign in to comment.