From a2194cc55e6469368e91dd38b388e86e2f7c0058 Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 15:17:25 +0100 Subject: [PATCH 1/7] chore: specify pauci version --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 8accd39..c1ee7c2 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "pauci/datetime", "description": "Enhanced DateTime, DateTimeImmutable and DateInterval objects", + "version": "0.7.0", "type": "library", "keywords": [ "datetime", From 5c418238f74cabfc0b72b0f2c4bbf366558e5d63 Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 15:32:39 +0100 Subject: [PATCH 2/7] chore: apply basic rector v 1.2.1 --- composer.json | 5 +++++ rector.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 rector.php diff --git a/composer.json b/composer.json index c1ee7c2..5faae79 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "phpstan/phpstan": "^1.9", "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.5", + "rector/rector": "^1.2", "squizlabs/php_codesniffer": "^3.7" }, "suggest": { @@ -58,12 +59,16 @@ "check": [ "@lint", "@cs-check", + "@rector", "@stan", "@test" ], "lint": "parallel-lint src tests", "cs-check": "phpcs", "cs-fix": "phpcbf", + "rector": "rector -n -vv", + "rector:clear": "rector -n --clear-cache -vv", + "rector:fix": "rector -vv", "stan": "phpstan analyse --no-progress", "test": "phpunit", "test-coverage": "phpunit --coverage-clover clover.xml" diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..50c3070 --- /dev/null +++ b/rector.php @@ -0,0 +1,14 @@ +withPhpSets(php82: true) + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); \ No newline at end of file From f35c36372c103f4d83bc1ebbc0db7a8eb7d59c32 Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 21:29:22 +0100 Subject: [PATCH 3/7] chore: composer update phpunit to v11 --- composer.json | 2 +- phpunit.xml.dist | 7 ++++++- src/FrozenClock.php | 4 +++- tests/src/DateTimeTest.php | 8 ++++---- tests/src/FrozenClockTest.php | 3 +-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 5faae79..92dca32 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "phpstan/extension-installer": "^1.2", "phpstan/phpstan": "^1.9", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^11.0.0", "rector/rector": "^1.2", "squizlabs/php_codesniffer": "^3.7" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a686948..ed19b24 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,10 @@ - + ./src diff --git a/src/FrozenClock.php b/src/FrozenClock.php index 97ecfb0..cb3050e 100644 --- a/src/FrozenClock.php +++ b/src/FrozenClock.php @@ -21,7 +21,9 @@ public function set(DateTime $now): void public function modify(string $modifier): void { $now = $this->now->modify($modifier); - \assert($now instanceof DateTime); + if ($now === false) { + throw new \RuntimeException("DateTimeImmutable::modify(): Failed to parse time string ({$modifier}) at position 0 (f): The timezone could not be found in the database"); + } $this->now = $now; } diff --git a/tests/src/DateTimeTest.php b/tests/src/DateTimeTest.php index d5fe41b..35008e3 100644 --- a/tests/src/DateTimeTest.php +++ b/tests/src/DateTimeTest.php @@ -189,11 +189,11 @@ public function testModify(): void public function testModifyFailed(): void { - $this->expectError(); - $this->expectErrorMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database'); - $dateTime = DateTime::fromString('2016-05-12 22:37:46+02:00'); - $dateTime->modify('foo'); + + $result = $dateTime->modify('foo'); + + self::assertFalse($result); } public function testSetDate(): void diff --git a/tests/src/FrozenClockTest.php b/tests/src/FrozenClockTest.php index 1692c28..422f206 100644 --- a/tests/src/FrozenClockTest.php +++ b/tests/src/FrozenClockTest.php @@ -51,8 +51,7 @@ public function testItFailsToModify(): void { $clock = new FrozenClock(); - $this->expectError(); - $this->expectErrorMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database'); + self::expectExceptionMessage('DateTimeImmutable::modify(): Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database'); $clock->modify('foo'); } From 8bbf90dda8094227d5aae92a6435872c2a4704a9 Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 21:31:39 +0100 Subject: [PATCH 4/7] feat: drop support for php v 8.0 --- .github/workflows/continuous-integration.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d827aee..43abf5b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -77,7 +77,7 @@ jobs: strategy: matrix: - php-versions: ['8.0', '8.1', '8.2'] + php-versions: ['8.1', '8.2'] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 92dca32..0b3434b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "issues": "https://github.com/pauci/datetime/issues" }, "require": { - "php": "^8.0 || ^8.1 || ^8.2", + "php": "^8.1 || ^8.2", "ext-json": "*", "psr/clock": "^1.0" }, From 091ba3dc7d0c83e9bad98500505e1e30e184aa66 Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 21:36:04 +0100 Subject: [PATCH 5/7] feat: Allow and test for php 8.3 --- .github/workflows/continuous-integration.yml | 6 +++--- composer.json | 2 +- rector.php | 2 +- src/FrozenClock.php | 4 +--- tests/src/DateTimeTest.php | 6 +++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 43abf5b..b20c69a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.2 + php-version: 8.3 coverage: none - name: Get composer cache directory @@ -52,7 +52,7 @@ jobs: uses: shivammathur/setup-php@v2 with: coverage: none - php-version: 8.2 + php-version: 8.3 - name: Get composer cache directory id: composer-cache @@ -77,7 +77,7 @@ jobs: strategy: matrix: - php-versions: ['8.1', '8.2'] + php-versions: ['8.1', '8.2', '8.3'] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 0b3434b..122027e 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "issues": "https://github.com/pauci/datetime/issues" }, "require": { - "php": "^8.1 || ^8.2", + "php": "^8.1 || ^8.2 || ^8.3", "ext-json": "*", "psr/clock": "^1.0" }, diff --git a/rector.php b/rector.php index 50c3070..8bfdc87 100644 --- a/rector.php +++ b/rector.php @@ -7,7 +7,7 @@ use Rector\Privatization; return RectorConfig::configure() - ->withPhpSets(php82: true) + ->withPhpSets(php83: true) ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', diff --git a/src/FrozenClock.php b/src/FrozenClock.php index cb3050e..97ecfb0 100644 --- a/src/FrozenClock.php +++ b/src/FrozenClock.php @@ -21,9 +21,7 @@ public function set(DateTime $now): void public function modify(string $modifier): void { $now = $this->now->modify($modifier); - if ($now === false) { - throw new \RuntimeException("DateTimeImmutable::modify(): Failed to parse time string ({$modifier}) at position 0 (f): The timezone could not be found in the database"); - } + \assert($now instanceof DateTime); $this->now = $now; } diff --git a/tests/src/DateTimeTest.php b/tests/src/DateTimeTest.php index 35008e3..31d144f 100644 --- a/tests/src/DateTimeTest.php +++ b/tests/src/DateTimeTest.php @@ -189,11 +189,11 @@ public function testModify(): void public function testModifyFailed(): void { - $dateTime = DateTime::fromString('2016-05-12 22:37:46+02:00'); + self::expectExceptionMessage('Failed to parse time string (foo) at position 0 (f): The timezone could not be found in the database'); - $result = $dateTime->modify('foo'); + $dateTime = DateTime::fromString('2016-05-12 22:37:46+02:00'); - self::assertFalse($result); + $dateTime->modify('foo'); } public function testSetDate(): void From cf07acc47d9f4fb96d77d6c84a6f0e6ed84828ab Mon Sep 17 00:00:00 2001 From: mmalac Date: Tue, 10 Dec 2024 21:58:42 +0100 Subject: [PATCH 6/7] feat: Allow and test for php 8.4 --- .github/workflows/continuous-integration.yml | 6 +++--- composer.json | 2 +- src/DateTime.php | 8 ++++---- src/FrozenClock.php | 5 +---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b20c69a..6d23be2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,7 +17,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: 8.4 coverage: none - name: Get composer cache directory @@ -52,7 +52,7 @@ jobs: uses: shivammathur/setup-php@v2 with: coverage: none - php-version: 8.3 + php-version: 8.4 - name: Get composer cache directory id: composer-cache @@ -77,7 +77,7 @@ jobs: strategy: matrix: - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 122027e..80c01fc 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "issues": "https://github.com/pauci/datetime/issues" }, "require": { - "php": "^8.1 || ^8.2 || ^8.3", + "php": "^8.1 || ^8.2 || ^8.3 || ^8.4", "ext-json": "*", "psr/clock": "^1.0" }, diff --git a/src/DateTime.php b/src/DateTime.php index 24a0575..3a00c31 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -42,7 +42,7 @@ public static function now(): DateTimeInterface /** * @throws Exception */ - public static function fromString(string $time, DateTimeZone $timezone = null): static + public static function fromString(string $time, ?DateTimeZone $timezone = null): static { $dateTime = parent::createFromInterface(new \DateTime($time, $timezone)); \assert($dateTime instanceof static); @@ -53,7 +53,7 @@ public static function fromString(string $time, DateTimeZone $timezone = null): /** * @throws Exception */ - public static function fromTimestamp(int $timestamp, DateTimeZone $timezone = null): static + public static function fromTimestamp(int $timestamp, ?DateTimeZone $timezone = null): static { $dateTime = static::createFromFormat('U', (string) $timestamp); \assert(false !== $dateTime); @@ -63,7 +63,7 @@ public static function fromTimestamp(int $timestamp, DateTimeZone $timezone = nu : $dateTime->inDefaultTimezone(); } - public static function fromFloatTimestamp(float $timestamp, DateTimeZone $timezone = null): static + public static function fromFloatTimestamp(float $timestamp, ?DateTimeZone $timezone = null): static { $integer = floor($timestamp); $fract = fmod($timestamp, 1); @@ -83,7 +83,7 @@ public static function fromFloatTimestamp(float $timestamp, DateTimeZone $timezo public static function createFromFormat( string $format, string $datetime, - DateTimeZone $timezone = null + ?DateTimeZone $timezone = null ): static|false { return parent::createFromFormat($format, $datetime, $timezone); } diff --git a/src/FrozenClock.php b/src/FrozenClock.php index 97ecfb0..bb6e136 100644 --- a/src/FrozenClock.php +++ b/src/FrozenClock.php @@ -6,11 +6,8 @@ class FrozenClock implements ClockInterface { - private DateTime $now; - - public function __construct(DateTime $now = null) + public function __construct(private DateTime $now = new DateTime()) { - $this->now = $now ?? new DateTime(); } public function set(DateTime $now): void From 662ac8578e83e0cc91ab5ddeb355a24afff5fce7 Mon Sep 17 00:00:00 2001 From: mmalac Date: Wed, 11 Dec 2024 22:38:51 +0100 Subject: [PATCH 7/7] feat: drop support for php v 8.1 and 8.2 --- .github/workflows/continuous-integration.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 6d23be2..5e416b1 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -77,7 +77,7 @@ jobs: strategy: matrix: - php-versions: ['8.1', '8.2', '8.3', '8.4'] + php-versions: ['8.3', '8.4'] steps: - name: Checkout code @@ -104,7 +104,7 @@ jobs: run: composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader - name: Run unit tests - run: ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml --coverage-text + run: ./vendor/bin/phpunit - name: Publish coverage report to Codecov uses: codecov/codecov-action@v1 diff --git a/composer.json b/composer.json index 80c01fc..0b00533 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "issues": "https://github.com/pauci/datetime/issues" }, "require": { - "php": "^8.1 || ^8.2 || ^8.3 || ^8.4", + "php": "^8.3 || ^8.4", "ext-json": "*", "psr/clock": "^1.0" },