diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08c9502..29dd245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: # —— Github Checkout 🔎 —————————————————————————————————————————————————— - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 @@ -55,7 +55,7 @@ jobs: steps: # —— Git Checkout PR branch —————————————————————————————————————————— - name: Git Checkout PR branch (${{ github.ref }}) - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 @@ -75,7 +75,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - name: Cache composer dependencies - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ matrix.symfony }} @@ -91,10 +91,14 @@ jobs: composer config extra.symfony.require "${{ matrix.symfony }}.*" composer update --no-progress --no-scripts -# # —— PHPStan —————————————————————————————————————————————————————————— -# - name: PHPStan (PHP Static Analysis) -# run: php vendor/phpstan/phpstan/phpstan.phar --memory-limit=1G - # —— Run tests ————————————————————————————————————————————————————————— - name: Run Tests run: php vendor/bin/phpunit + + # —— PHPStan ——————————————————————————————————————————————————————————— + - name: PHPStan (static analysis) + run: php vendor/bin/phpstan analyse --no-progress + + # —— Rector ———————————————————————————————————————————————————————————— + - name: Rector (dry-run) + run: php vendor/bin/rector process --dry-run --no-progress-bar diff --git a/composer.json b/composer.json index 6f35611..d9a64fa 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "require": { "php": "^8.2", "ext-json": "*", - "phpdocumentor/reflection-docblock": "^5.3", "symfony/debug-bundle": "^6.4|^7.4|^8.0", "symfony/http-client": "^6.4|^7.4|^8.0", "symfony/property-access": "^6.4|^7.4|^8.0", @@ -22,8 +21,9 @@ }, "require-dev" : { "friendsofphp/php-cs-fixer": "^3.15", - "phpstan/phpstan": "^1.8.7", - "phpunit/phpunit": "^9.5|^10.0", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^11.0|^12.0|^13.0", + "rector/rector": "^2.0", "symfony/var-dumper": "^6.4|^7.4|^8.0" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon index 8c3efb2..f58e532 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,5 +3,7 @@ parameters: paths: - src - tests - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false + ignoreErrors: + # PHPStan 2.0 removed the `checkMissingIterableValueType` parameter; + # keep the project's original opt-out via the equivalent identifier. + - identifier: missingType.iterableValue diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c0e0e76..0ed11d5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - - - - ./src/ - - + ./tests/ + + + ./src/ + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ab61176 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + // Target the lowest supported PHP version so generated code stays + // compatible with every consumer (composer.json requires php ^8.2). + ->withPhpSets(php82: true) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + earlyReturn: true, + ); diff --git a/src/Resource/AbsoluteTimeWindow.php b/src/Resource/AbsoluteTimeWindow.php index acdbe4c..52d2978 100644 --- a/src/Resource/AbsoluteTimeWindow.php +++ b/src/Resource/AbsoluteTimeWindow.php @@ -6,13 +6,7 @@ final class AbsoluteTimeWindow implements TimeWindowInterface { - public \DateTimeImmutable $start; - - public \DateTimeImmutable $end; - - public function __construct(\DateTimeImmutable $start, \DateTimeImmutable $end) + public function __construct(public \DateTimeImmutable $start, public \DateTimeImmutable $end) { - $this->start = $start; - $this->end = $end; } } diff --git a/src/Resource/RelativeTimeWindow.php b/src/Resource/RelativeTimeWindow.php index c41e628..f139411 100644 --- a/src/Resource/RelativeTimeWindow.php +++ b/src/Resource/RelativeTimeWindow.php @@ -6,13 +6,7 @@ final class RelativeTimeWindow implements TimeWindowInterface { - public int $start; - - public int $end; - - public function __construct(int $start, int $end) + public function __construct(public int $start, public int $end) { - $this->start = $start; - $this->end = $end; } } diff --git a/src/Resource/ShipmentStep.php b/src/Resource/ShipmentStep.php index 634779d..7ae55b1 100644 --- a/src/Resource/ShipmentStep.php +++ b/src/Resource/ShipmentStep.php @@ -6,8 +6,6 @@ class ShipmentStep { - public int $id; - public string $description; public Location $location; @@ -23,8 +21,7 @@ class ShipmentStep */ public array $timeWindows; - public function __construct(int $id) + public function __construct(public int $id) { - $this->id = $id; } } diff --git a/src/Resource/Vehicle.php b/src/Resource/Vehicle.php index f3b0046..51b7371 100644 --- a/src/Resource/Vehicle.php +++ b/src/Resource/Vehicle.php @@ -9,8 +9,6 @@ */ final class Vehicle { - public int $id; - public string $profile; public string $description; @@ -52,8 +50,7 @@ final class Vehicle public array $steps; - public function __construct(int $id) + public function __construct(public int $id) { - $this->id = $id; } } diff --git a/src/Serializer.php b/src/Serializer.php index fc54bf1..0a2cc25 100644 --- a/src/Serializer.php +++ b/src/Serializer.php @@ -34,6 +34,8 @@ public function __construct() } /** + * @return \ArrayObject|array|string|int|float|bool|null + * * @throws SerializerExceptionInterface */ public function normalize(mixed $data, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null diff --git a/src/Serializer/Normalizer/LocationNormalizer.php b/src/Serializer/Normalizer/LocationNormalizer.php index 7048399..77e6fd7 100644 --- a/src/Serializer/Normalizer/LocationNormalizer.php +++ b/src/Serializer/Normalizer/LocationNormalizer.php @@ -21,9 +21,6 @@ public function normalize(mixed $object, ?string $format = null, array $context ]; } - /** - * @param Location $data - */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Location; diff --git a/src/Serializer/Normalizer/TimeWindowNormalizer.php b/src/Serializer/Normalizer/TimeWindowNormalizer.php index 2c3b599..d4f8b1d 100644 --- a/src/Serializer/Normalizer/TimeWindowNormalizer.php +++ b/src/Serializer/Normalizer/TimeWindowNormalizer.php @@ -34,9 +34,6 @@ public function normalize(mixed $object, ?string $format = null, array $context return null; } - /** - * @param TimeWindowInterface $data - */ public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof TimeWindowInterface; diff --git a/src/Util/DateTimeUtil.php b/src/Util/DateTimeUtil.php index 6e04d81..df6f89b 100644 --- a/src/Util/DateTimeUtil.php +++ b/src/Util/DateTimeUtil.php @@ -13,9 +13,8 @@ public static function fromUTC(\DateTimeImmutable $dateTime): \DateTimeImmutable $localDateTime = new \DateTimeImmutable(); $localDateTime = $localDateTime->setDate((int) $dateTime->format('Y'), (int) $dateTime->format('m'), (int) $dateTime->format('d')); - $localDateTime = $localDateTime->seTTime((int) $dateTime->format('H'), (int) $dateTime->format('i'), (int) $dateTime->format('s')); - return $localDateTime; + return $localDateTime->seTTime((int) $dateTime->format('H'), (int) $dateTime->format('i'), (int) $dateTime->format('s')); } public static function toUTC(\DateTimeImmutable $dateTime): \DateTimeImmutable @@ -23,8 +22,7 @@ public static function toUTC(\DateTimeImmutable $dateTime): \DateTimeImmutable $localDateTime = new \DateTimeImmutable(); $localDateTime = $localDateTime->setTimezone(new \DateTimeZone('UTC')); $localDateTime = $localDateTime->setDate((int) $dateTime->format('Y'), (int) $dateTime->format('m'), (int) $dateTime->format('d')); - $localDateTime = $localDateTime->seTTime((int) $dateTime->format('H'), (int) $dateTime->format('i'), (int) $dateTime->format('s')); - return $localDateTime; + return $localDateTime->seTTime((int) $dateTime->format('H'), (int) $dateTime->format('i'), (int) $dateTime->format('s')); } }