Skip to content

Commit

Permalink
Compatibility with PHP 8.0 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz authored Apr 19, 2022
1 parent 6fb9897 commit 488e081
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 46 deletions.
67 changes: 56 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
name: CI

on: [pull_request]
on: [pull_request, workflow_dispatch]

jobs:
checks:
phpstan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
- 7.4
- 8.0
- 8.1

steps:
- name: Checkout
Expand All @@ -13,9 +20,8 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: ${{ matrix.php-version }}
extensions: mbstring
coverage: xdebug

- name: Get composer cache directory
id: composercache
Expand All @@ -31,18 +37,58 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist

- name: Run phpstan
- name: Run PHPStan
run: composer phpstan

- name: Run code-sniffer

phpcs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
- 7.4

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHP CodeSniffer
run: composer phpcs

tests:

phpunit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [ '7.4' ]
php-version:
- 7.4
- 8.0
- 8.1
composer-arg:
- install
- update --prefer-lowest

steps:
- name: Checkout
Expand All @@ -67,8 +113,7 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
run: composer ${{ matrix.composer-arg }} --prefer-dist

- name: Run phpunit
- name: Run PHPUnit
run: composer phpunit

10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"roave/security-advisories": "dev-master"
},
"scripts": {
"phpcs": "vendor/bin/phpcs --standard=BrandEmbassyCodingStandard src",
"phpcbf": "./vendor/bin/phpcbf --standard=BrandEmbassyCodingStandard src",
"phpcs": "vendor/bin/phpcs --standard=BrandEmbassyCodingStandard src --runtime-set php_version 70400",
"phpcbf": "./vendor/bin/phpcbf --standard=BrandEmbassyCodingStandard src --runtime-set php_version 70400",
"phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon src",
"phpunit": "./vendor/bin/phpunit src --no-coverage",
"phpunit-cc": "./vendor/bin/phpunit src",
Expand All @@ -31,6 +31,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
"sort-packages": true,
"lock": false,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
5 changes: 4 additions & 1 deletion src/AmountOfTime/AmountOfTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use InvalidArgumentException;
use function floor;

final class AmountOfTime
/**
* @final
*/
class AmountOfTime
{
private const SECOND_IN_MILLISECOND = 1000;

Expand Down
5 changes: 4 additions & 1 deletion src/AmountOfTime/AmountOfTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class AmountOfTimeTest extends TestCase
/**
* @final
*/
class AmountOfTimeTest extends TestCase
{
/**
* @dataProvider millisecondsProvider
Expand Down
5 changes: 4 additions & 1 deletion src/AmountOfTime/TimeInSeconds.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use Nette\StaticClass;
use Nette\Utils\DateTime;

final class TimeInSeconds
/**
* @final
*/
class TimeInSeconds
{
use StaticClass;

Expand Down
5 changes: 4 additions & 1 deletion src/DateTimeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use function assert;
use function method_exists;

final class DateTimeFormatter
/**
* @final
*/
class DateTimeFormatter
{
public static function formatAs(DateTimeInterface $dateTime, string $format): string
{
Expand Down
13 changes: 8 additions & 5 deletions src/DateTimeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class DateTimeFormatterTest extends TestCase
/**
* @final
*/
class DateTimeFormatterTest extends TestCase
{
private const DATETIME_WITHOUT_MILLISECONDS = '2017-05-10T12:13:14+02:00';
private const DATETIME_WITH_MILLISECONDS = '2017-05-10T12:13:14.000+02:00';
Expand Down Expand Up @@ -47,7 +50,7 @@ public function testFormatInTimezoneAs(DateTimeInterface $dateTime): void
$formattedDateTime = DateTimeFormatter::formatInTimezoneAs(
$dateTime,
new DateTimeZone('UTC'),
DateTime::ATOM
DateTime::ATOM,
);

Assert::assertSame($expectedUtcFormat, $formattedDateTime);
Expand Down Expand Up @@ -108,7 +111,7 @@ public function testFormatTimestampInTimezoneAs(): void
$formattedDateTime = DateTimeFormatter::formatTimestampInTimezoneAs(
1496237560,
new DateTimeZone('Europe/Prague'),
DateTime::ATOM
DateTime::ATOM,
);

Assert::assertSame('2017-05-31T15:32:40+02:00', $formattedDateTime);
Expand All @@ -119,7 +122,7 @@ public function testFormatTimestampInTimezone(): void
{
$formattedDateTime = DateTimeFormatter::formatTimestampInTimezone(
1496237560,
new DateTimeZone('Europe/Prague')
new DateTimeZone('Europe/Prague'),
);

Assert::assertSame('2017-05-31T15:32:40+02:00', $formattedDateTime);
Expand All @@ -130,7 +133,7 @@ public function testFormatTimestampWithMillisecondsInTimezone(): void
{
$formattedDateTime = DateTimeFormatter::formatTimestampWithMillisecondsInTimezone(
1496237560456,
new DateTimeZone('Europe/Prague')
new DateTimeZone('Europe/Prague'),
);

Assert::assertSame('2017-05-31T15:32:40.456+02:00', $formattedDateTime);
Expand Down
9 changes: 6 additions & 3 deletions src/DateTimeFromString.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
use function assert;
use function is_array;

final class DateTimeFromString
/**
* @final
*/
class DateTimeFromString
{
/**
* @throws InvalidDateTimeStringException
Expand All @@ -36,7 +39,7 @@ public static function createWithMilliseconds(string $dateTimeStringInRfc3339Ext
{
$format = Rfc3339ExtendedFormat::getInputFormat();
$dateTimeStringInRfc3339ExtendedString = NanosecondsToMicrosecondsFormatHelper::normalizeInputIfNeeded(
$dateTimeStringInRfc3339ExtendedString
$dateTimeStringInRfc3339ExtendedString,
);

return self::createFromFormat($format, $dateTimeStringInRfc3339ExtendedString);
Expand Down Expand Up @@ -81,7 +84,7 @@ private static function assertValidDateTime(
throw InvalidDateTimeStringException::byValidationErrors(
$originalDateTimeString,
$lastErrors['errors'],
$lastErrors['warnings']
$lastErrors['warnings'],
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/DateTimeFromStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use PHPUnit\Framework\TestCase;
use function sprintf;

final class DateTimeFromStringTest extends TestCase
/**
* @final
*/
class DateTimeFromStringTest extends TestCase
{
/**
* @dataProvider dateTimeInFormatProvider
Expand Down Expand Up @@ -160,7 +163,7 @@ public function testThrowExceptionWhenCannotCreateDateTime(): void
{
$this->expectException(InvalidDateTimeStringException::class);
$this->expectExceptionMessage(
"Can't convert '2020-12-05T02:50:16.123+03:00' to datetime using format Y-m-d\TH:i:sP."
"Can't convert '2020-12-05T02:50:16.123+03:00' to datetime using format Y-m-d\TH:i:sP.",
);

DateTimeFromString::create('2020-12-05T02:50:16.123+03:00');
Expand All @@ -173,8 +176,8 @@ public function testThrowExceptionWhenCannotCreateDateTimeWithMilliseconds(): vo
$this->expectExceptionMessage(
sprintf(
"Can't convert '2020-12-05T02:50:16+03:00' to datetime using format %s.",
Rfc3339ExtendedFormat::getInputFormat()
)
Rfc3339ExtendedFormat::getInputFormat(),
),
);

DateTimeFromString::createWithMilliseconds('2020-12-05T02:50:16+03:00');
Expand Down
5 changes: 4 additions & 1 deletion src/DateTimeFromTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use InvalidArgumentException;
use function sprintf;

final class DateTimeFromTimestamp
/**
* @final
*/
class DateTimeFromTimestamp
{
/**
* @throws InvalidArgumentException
Expand Down
5 changes: 4 additions & 1 deletion src/DateTimeModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use DateTimeZone;
use Nette\StaticClass;

final class DateTimeModifier
/**
* @final
*/
class DateTimeModifier
{
use StaticClass;

Expand Down
17 changes: 10 additions & 7 deletions src/DateTimeModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class DateTimeModifierTest extends TestCase
/**
* @final
*/
class DateTimeModifierTest extends TestCase
{
/**
* @dataProvider getBeginningOfTheDayDataProvider
Expand All @@ -18,7 +21,7 @@ public function testGetBeginningOfTheDay(string $expectedAtom, string $originAto

Assert::assertSame(
DateTimeFormatter::format($expectedDateTime),
DateTimeFormatter::format(DateTimeModifier::getBeginningOfTheDay($originDateTime))
DateTimeFormatter::format(DateTimeModifier::getBeginningOfTheDay($originDateTime)),
);
}

Expand Down Expand Up @@ -55,8 +58,8 @@ public function testGetBeginningOfTheDayInTimezone(
Assert::assertSame(
DateTimeFormatter::format($expectedDateTime),
DateTimeFormatter::format(
DateTimeModifier::getBeginningOfTheDayInTimezone($originDateTime, $dateTimeZone)
)
DateTimeModifier::getBeginningOfTheDayInTimezone($originDateTime, $dateTimeZone),
),
);
}

Expand Down Expand Up @@ -101,7 +104,7 @@ public function testGetEndOfTheDay(string $expectedAtom, string $originAtom): vo

Assert::assertSame(
DateTimeFormatter::format($expectedDateTime),
DateTimeFormatter::format(DateTimeModifier::getEndOfTheDay($originDateTime))
DateTimeFormatter::format(DateTimeModifier::getEndOfTheDay($originDateTime)),
);
}

Expand Down Expand Up @@ -138,8 +141,8 @@ public function testGetEndOfTheDayInTimezone(
Assert::assertSame(
DateTimeFormatter::format($expectedDateTime),
DateTimeFormatter::format(
DateTimeModifier::getEndOfTheDayInTimezone($originDateTime, $dateTimeZone)
)
DateTimeModifier::getEndOfTheDayInTimezone($originDateTime, $dateTimeZone),
),
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Doctrine/DateTimeImmutableAsTimestampDoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use InvalidArgumentException;
use function is_float;

final class DateTimeImmutableAsTimestampDoctrineType extends Type
/**
* @final
*/
class DateTimeImmutableAsTimestampDoctrineType extends Type
{
public const NAME = 'datetime_immutable_as_timestamp';

Expand Down
5 changes: 4 additions & 1 deletion src/Format/NanosecondsToMicrosecondsFormatHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use function implode;
use function preg_match;

final class NanosecondsToMicrosecondsFormatHelper
/**
* @final
*/
class NanosecondsToMicrosecondsFormatHelper
{
private const MICROSECONDS_AND_TIMEZONE_PATTERN = '/^(^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d{6})\d*(Z|(?:\+|\-)[0,1]\d:00)$/';

Expand Down
5 changes: 4 additions & 1 deletion src/Format/NanosecondsToMicrosecondsFormatHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class NanosecondsToMicrosecondsFormatHelperTest extends TestCase
/**
* @final
*/
class NanosecondsToMicrosecondsFormatHelperTest extends TestCase
{
/**
* @dataProvider dateTimeAsStringProvider
Expand Down
Loading

0 comments on commit 488e081

Please sign in to comment.