diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5e416b1..ac7327f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -6,105 +6,60 @@ on: branches: - master +env: + default_php: 8.4 + jobs: coding-standards: name: Coding Standards runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - uses: actions/checkout@v4.2.2 + - uses: shivammathur/setup-php@2.34.1 with: - php-version: 8.4 + php-version: ${{ env.default_php }} coverage: none - - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --no-interaction --no-progress --prefer-dist - - - name: Run the linter - run: composer lint - - - name: Check coding standards - run: composer cs-check + - uses: ramsey/composer-install@v3 + - run: composer lint + - run: composer cs-check static-analysis: name: Static Analysis runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - uses: actions/checkout@v4.2.2 + - uses: shivammathur/setup-php@2.34.1 with: coverage: none - php-version: 8.4 - - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer update --no-interaction --no-progress --prefer-dist - - - name: Run static analysis - run: php vendor/bin/phpstan analyse + php-version: ${{ env.default_php }} + - uses: ramsey/composer-install@v3 + - run: php vendor/bin/phpstan analyse unit-tests: name: Unit Tests runs-on: ubuntu-latest - strategy: matrix: php-versions: ['8.3', '8.4'] steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - uses: actions/checkout@v4.2.2 + - uses: shivammathur/setup-php@2.34.1 with: php-version: "${{ matrix.php-versions }}" coverage: xdebug + - uses: ramsey/composer-install@v3 + - run: ./vendor/bin/phpunit + - uses: codecov/codecov-action@v1 - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 + rector: + runs-on: ubuntu-latest + name: Run Rector on PHP + steps: + - uses: actions/checkout@v4.2.2 + - uses: shivammathur/setup-php@2.34.1 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --no-interaction --no-progress --prefer-dist --optimize-autoloader - - - name: Run unit tests - run: ./vendor/bin/phpunit - - - name: Publish coverage report to Codecov - uses: codecov/codecov-action@v1 + php-version: ${{ env.default_php }} + tools: composer + - uses: ramsey/composer-install@v3 + - run: composer rector diff --git a/composer.json b/composer.json index 21e750e..679286a 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,12 @@ }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.9", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^11.0.0", - "rector/rector": "^1.2", - "squizlabs/php_codesniffer": "^3.7" + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^12.0", + "rector/rector": "^2.0", + "squizlabs/php_codesniffer": "^4.0" }, "suggest": { "pauci/datetime-doctrine": "Allows the use of pauci/datetime value objects as Doctrine field types." diff --git a/src/DateTime.php b/src/DateTime.php index 516c7f5..e1d83fb 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -44,10 +44,7 @@ public static function now(): DateTimeInterface */ public static function fromString(string $time, ?DateTimeZone $timezone = null): static { - $dateTime = parent::createFromInterface(new \DateTime($time, $timezone)); - \assert($dateTime instanceof static); - - return $dateTime; + return parent::createFromInterface(new \DateTime($time, $timezone)); } /** @@ -100,10 +97,7 @@ public static function createFromMutable(\DateTime $object): static #[\Override] public static function createFromInterface(\DateTimeInterface $object): static { - $dateTime = parent::createFromInterface($object); - \assert($dateTime instanceof static); - - return $dateTime; + return parent::createFromInterface($object); } /** diff --git a/src/FrozenClock.php b/src/FrozenClock.php index 234ca11..21f4688 100644 --- a/src/FrozenClock.php +++ b/src/FrozenClock.php @@ -18,7 +18,6 @@ public function set(DateTime $now): void public function modify(string $modifier): void { $now = $this->now->modify($modifier); - \assert($now instanceof DateTime); $this->now = $now; } diff --git a/tests/src/DateIntervalTest.php b/tests/src/DateIntervalTest.php index 7590c87..c29b1de 100644 --- a/tests/src/DateIntervalTest.php +++ b/tests/src/DateIntervalTest.php @@ -36,8 +36,6 @@ public function testFromDateInterval(string $intervalSpec, array $parts): void { $interval = DateInterval::fromDateInterval(new \DateInterval($intervalSpec)); - self::assertInstanceOf(DateInterval::class, $interval); - self::assertEquals($parts[0], $interval->y); self::assertEquals($parts[1], $interval->m); self::assertEquals($parts[2], $interval->d); @@ -57,9 +55,7 @@ public function testFromDateIntervalBetweenWinterAndDst(): void $interval = DateInterval::fromDateInterval($phpInterval); - $expected = PHP_VERSION_ID >= 80100 ? 'P2M30DT23H' : 'P3MT-1H'; - - self::assertEquals($expected, (string) $interval); + self::assertEquals('P2M30DT23H', (string) $interval); } /** diff --git a/tests/src/DateTimeTest.php b/tests/src/DateTimeTest.php index 31d144f..4c6ccfa 100644 --- a/tests/src/DateTimeTest.php +++ b/tests/src/DateTimeTest.php @@ -45,7 +45,6 @@ public function testFromString(): void { $dateTime = DateTime::fromString('2017-12-02 02:20:03'); - self::assertInstanceOf(DateTime::class, $dateTime); self::assertEquals('2017-12-02T02:20:03+01:00', (string) $dateTime); } @@ -83,7 +82,6 @@ public function testCreateFromMutable(): void { $dateTime = DateTime::createFromMutable(new \DateTime('2016-05-16 14:09:10')); - self::assertInstanceOf(DateTime::class, $dateTime); self::assertEquals('2016-05-16T14:09:10+02:00', (string) $dateTime); $dateTime = DateTime::createFromMutable(new \DateTime('2016-05-16 14:09:10-04:00')); @@ -120,7 +118,6 @@ public function testCreateFromInterface(): void $phpDateTime = new \DateTime('2016-05-16 14:32:51.678991'); $dateTime = DateTime::createFromInterface($phpDateTime); - self::assertInstanceOf(DateTime::class, $dateTime); self::assertEquals('2016-05-16T14:32:51.678991+02:00', (string) $dateTime); } @@ -154,7 +151,6 @@ public function testAdd(): void $dateTime2 = $dateTime1->add($interval); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-13T22:37:46+02:00', (string) $dateTime2); // Immutability check @@ -168,7 +164,6 @@ public function testSub(): void $dateTime2 = $dateTime1->sub($interval); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-11T22:37:46+02:00', (string) $dateTime2); // Immutability check @@ -180,7 +175,6 @@ public function testModify(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00'); $dateTime2 = $dateTime1->modify('+1 day'); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-13T22:37:46+02:00', (string) $dateTime2); // Immutability check @@ -201,7 +195,6 @@ public function testSetDate(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00'); $dateTime2 = $dateTime1->setDate(2011, 10, 22); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2011-10-22T22:37:46+02:00', (string) $dateTime2); // Immutability check @@ -213,7 +206,6 @@ public function testSetISODate(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00'); $dateTime2 = $dateTime1->setISODate(2011, 42, 6); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2011-10-22T22:37:46+02:00', (string) $dateTime2); // Immutability check @@ -225,7 +217,6 @@ public function testSetTime(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46.123456+02:00'); $dateTime2 = $dateTime1->setTime(12, 10, 15, 98765); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-12T12:10:15.098765+02:00', (string) $dateTime2); // Immutability check @@ -237,7 +228,6 @@ public function testSetTimestamp(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00'); $dateTime2 = $dateTime1->setTimestamp(1463490311); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-17T15:05:11+02:00', (string) $dateTime2); // Immutability check @@ -249,7 +239,6 @@ public function testSetTimezone(): void $dateTime1 = DateTime::fromString('2016-05-12 22:37:46+02:00'); $dateTime2 = $dateTime1->setTimezone(new \DateTimeZone('America/New_York')); - self::assertInstanceOf(DateTime::class, $dateTime2); self::assertEquals('2016-05-12T16:37:46-04:00', (string) $dateTime2); // Immutability check