diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aafea40..ade53db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 @@ -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 @@ -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 - diff --git a/composer.json b/composer.json index 8b29ab8..0558330 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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 + } } } diff --git a/src/AmountOfTime/AmountOfTime.php b/src/AmountOfTime/AmountOfTime.php index 7a658e6..594a2b1 100644 --- a/src/AmountOfTime/AmountOfTime.php +++ b/src/AmountOfTime/AmountOfTime.php @@ -5,7 +5,10 @@ use InvalidArgumentException; use function floor; -final class AmountOfTime +/** + * @final + */ +class AmountOfTime { private const SECOND_IN_MILLISECOND = 1000; diff --git a/src/AmountOfTime/AmountOfTimeTest.php b/src/AmountOfTime/AmountOfTimeTest.php index c645b69..4d17e53 100644 --- a/src/AmountOfTime/AmountOfTimeTest.php +++ b/src/AmountOfTime/AmountOfTimeTest.php @@ -5,7 +5,10 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; -final class AmountOfTimeTest extends TestCase +/** + * @final + */ +class AmountOfTimeTest extends TestCase { /** * @dataProvider millisecondsProvider diff --git a/src/AmountOfTime/TimeInSeconds.php b/src/AmountOfTime/TimeInSeconds.php index 41a9eaf..6bfc8bd 100644 --- a/src/AmountOfTime/TimeInSeconds.php +++ b/src/AmountOfTime/TimeInSeconds.php @@ -5,7 +5,10 @@ use Nette\StaticClass; use Nette\Utils\DateTime; -final class TimeInSeconds +/** + * @final + */ +class TimeInSeconds { use StaticClass; diff --git a/src/DateTimeFormatter.php b/src/DateTimeFormatter.php index 1a3bfc4..8e95f9b 100644 --- a/src/DateTimeFormatter.php +++ b/src/DateTimeFormatter.php @@ -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 { diff --git a/src/DateTimeFormatterTest.php b/src/DateTimeFormatterTest.php index 44474ff..f89cdfc 100644 --- a/src/DateTimeFormatterTest.php +++ b/src/DateTimeFormatterTest.php @@ -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'; @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/src/DateTimeFromString.php b/src/DateTimeFromString.php index c64bf70..3e525ba 100644 --- a/src/DateTimeFromString.php +++ b/src/DateTimeFromString.php @@ -10,7 +10,10 @@ use function assert; use function is_array; -final class DateTimeFromString +/** + * @final + */ +class DateTimeFromString { /** * @throws InvalidDateTimeStringException @@ -36,7 +39,7 @@ public static function createWithMilliseconds(string $dateTimeStringInRfc3339Ext { $format = Rfc3339ExtendedFormat::getInputFormat(); $dateTimeStringInRfc3339ExtendedString = NanosecondsToMicrosecondsFormatHelper::normalizeInputIfNeeded( - $dateTimeStringInRfc3339ExtendedString + $dateTimeStringInRfc3339ExtendedString, ); return self::createFromFormat($format, $dateTimeStringInRfc3339ExtendedString); @@ -81,7 +84,7 @@ private static function assertValidDateTime( throw InvalidDateTimeStringException::byValidationErrors( $originalDateTimeString, $lastErrors['errors'], - $lastErrors['warnings'] + $lastErrors['warnings'], ); } } diff --git a/src/DateTimeFromStringTest.php b/src/DateTimeFromStringTest.php index d54747b..1cc28c7 100644 --- a/src/DateTimeFromStringTest.php +++ b/src/DateTimeFromStringTest.php @@ -9,7 +9,10 @@ use PHPUnit\Framework\TestCase; use function sprintf; -final class DateTimeFromStringTest extends TestCase +/** + * @final + */ +class DateTimeFromStringTest extends TestCase { /** * @dataProvider dateTimeInFormatProvider @@ -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'); @@ -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'); diff --git a/src/DateTimeFromTimestamp.php b/src/DateTimeFromTimestamp.php index 4c5f085..8bda0b2 100644 --- a/src/DateTimeFromTimestamp.php +++ b/src/DateTimeFromTimestamp.php @@ -6,7 +6,10 @@ use InvalidArgumentException; use function sprintf; -final class DateTimeFromTimestamp +/** + * @final + */ +class DateTimeFromTimestamp { /** * @throws InvalidArgumentException diff --git a/src/DateTimeModifier.php b/src/DateTimeModifier.php index 7ee3a69..45d9b95 100644 --- a/src/DateTimeModifier.php +++ b/src/DateTimeModifier.php @@ -6,7 +6,10 @@ use DateTimeZone; use Nette\StaticClass; -final class DateTimeModifier +/** + * @final + */ +class DateTimeModifier { use StaticClass; diff --git a/src/DateTimeModifierTest.php b/src/DateTimeModifierTest.php index 5fc5fb3..2305583 100644 --- a/src/DateTimeModifierTest.php +++ b/src/DateTimeModifierTest.php @@ -6,7 +6,10 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; -final class DateTimeModifierTest extends TestCase +/** + * @final + */ +class DateTimeModifierTest extends TestCase { /** * @dataProvider getBeginningOfTheDayDataProvider @@ -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)), ); } @@ -55,8 +58,8 @@ public function testGetBeginningOfTheDayInTimezone( Assert::assertSame( DateTimeFormatter::format($expectedDateTime), DateTimeFormatter::format( - DateTimeModifier::getBeginningOfTheDayInTimezone($originDateTime, $dateTimeZone) - ) + DateTimeModifier::getBeginningOfTheDayInTimezone($originDateTime, $dateTimeZone), + ), ); } @@ -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)), ); } @@ -138,8 +141,8 @@ public function testGetEndOfTheDayInTimezone( Assert::assertSame( DateTimeFormatter::format($expectedDateTime), DateTimeFormatter::format( - DateTimeModifier::getEndOfTheDayInTimezone($originDateTime, $dateTimeZone) - ) + DateTimeModifier::getEndOfTheDayInTimezone($originDateTime, $dateTimeZone), + ), ); } diff --git a/src/Doctrine/DateTimeImmutableAsTimestampDoctrineType.php b/src/Doctrine/DateTimeImmutableAsTimestampDoctrineType.php index 8b64545..9e37c94 100644 --- a/src/Doctrine/DateTimeImmutableAsTimestampDoctrineType.php +++ b/src/Doctrine/DateTimeImmutableAsTimestampDoctrineType.php @@ -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'; diff --git a/src/Format/NanosecondsToMicrosecondsFormatHelper.php b/src/Format/NanosecondsToMicrosecondsFormatHelper.php index 882b12c..a2d40c3 100644 --- a/src/Format/NanosecondsToMicrosecondsFormatHelper.php +++ b/src/Format/NanosecondsToMicrosecondsFormatHelper.php @@ -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)$/'; diff --git a/src/Format/NanosecondsToMicrosecondsFormatHelperTest.php b/src/Format/NanosecondsToMicrosecondsFormatHelperTest.php index 09908db..3ac39cd 100644 --- a/src/Format/NanosecondsToMicrosecondsFormatHelperTest.php +++ b/src/Format/NanosecondsToMicrosecondsFormatHelperTest.php @@ -5,7 +5,10 @@ use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; -final class NanosecondsToMicrosecondsFormatHelperTest extends TestCase +/** + * @final + */ +class NanosecondsToMicrosecondsFormatHelperTest extends TestCase { /** * @dataProvider dateTimeAsStringProvider diff --git a/src/Format/Rfc3339ExtendedFormat.php b/src/Format/Rfc3339ExtendedFormat.php index b9ec48c..bd0d642 100644 --- a/src/Format/Rfc3339ExtendedFormat.php +++ b/src/Format/Rfc3339ExtendedFormat.php @@ -4,7 +4,10 @@ use DateTime; -final class Rfc3339ExtendedFormat +/** + * @final + */ +class Rfc3339ExtendedFormat { public static function getOutputFormat(): string { diff --git a/src/InvalidDateTimeStringException.php b/src/InvalidDateTimeStringException.php index 5cdc425..deb8a1c 100644 --- a/src/InvalidDateTimeStringException.php +++ b/src/InvalidDateTimeStringException.php @@ -6,7 +6,10 @@ use function array_values; use function sprintf; -final class InvalidDateTimeStringException extends InvalidArgumentException +/** + * @final + */ +class InvalidDateTimeStringException extends InvalidArgumentException { /** * @var string[] @@ -26,7 +29,7 @@ public static function byNoDatetimeString( $message = sprintf( "Can't convert '%s' to datetime using format %s.", $dateTimeStringInNotRecognizedFormat, - $requiredFormat + $requiredFormat, ); return new self($message); diff --git a/src/StringFromNow.php b/src/StringFromNow.php index 32f145f..6ecfb16 100644 --- a/src/StringFromNow.php +++ b/src/StringFromNow.php @@ -4,7 +4,10 @@ use DateTimeZone; -final class StringFromNow +/** + * @final + */ +class StringFromNow { private DateTimeImmutableFactory $dateTimeImmutableFactory;