From a9e0bd1cf54854633ac8e913d99ec39c41e422b3 Mon Sep 17 00:00:00 2001 From: gbprod Date: Tue, 16 Jan 2024 09:00:00 +0100 Subject: [PATCH] feat: support symfony 7 (#34) Ref: #33 --- .github/workflows/ci.yaml | 83 +++++++++++++++++++++------------------ composer.json | 6 +-- src/UuidDenormalizer.php | 20 ++++++---- src/UuidNormalizer.php | 27 ++++++++----- 4 files changed, 76 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7796b66..200f742 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,44 +1,49 @@ name: Tests on: - push: - branches: [master] - pull_request: - branches: [master] - schedule: - - cron: "0 7 * * 1" + push: + branches: [master] + pull_request: + branches: [master] + schedule: + - cron: '0 7 * * 1' jobs: - unit-tests: - runs-on: ubuntu-latest - strategy: - matrix: - php: ["7.4", "8.0", "8.1"] - sf: ["5.4.*", "6.0.*", "6.1.*"] - exclude: - - php: "7.4" - sf: "6.1.*" - - php: "8.0" - sf: "6.1.*" - - php: "7.4" - sf: "6.0.*" - steps: - - uses: actions/checkout@v2 - - uses: php-actions/composer@v6 - with: - php_version: "${{ matrix.php }}" - command: require symfony/serializer:${{ matrix.sf }} --no-update - - uses: php-actions/composer@v6 - with: - php_version: "${{ matrix.php }}" - command: update - - uses: php-actions/phpunit@v3 - with: - configuration: phpunit.xml.dist - memory_limit: 256M - php_version: "${{ matrix.php }}" - - uses: php-actions/phpstan@v3 - with: - php_version: "${{ matrix.php }}" - level: max - path: src/ + unit-tests: + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.4', '8.0', '8.1', '8.2'] + sf: ['5.4.*', '6.4.*', '7.0.*'] + exclude: + - php: '7.4' + sf: '6.4.*' + - php: '8.0' + sf: '6.4.*' + - php: '7.4' + sf: '7.0.*' + - php: '8.0' + sf: '7.0.*' + - php: '8.1' + sf: '7.0.*' + steps: + - uses: actions/checkout@v2 + - uses: php-actions/composer@v6 + with: + php_version: '${{ matrix.php }}' + command: require symfony/serializer:${{ matrix.sf }} --no-update + - uses: php-actions/composer@v6 + with: + php_version: '${{ matrix.php }}' + command: update + - uses: php-actions/phpunit@v3 + with: + configuration: phpunit.xml.dist + memory_limit: 256M + php_version: '${{ matrix.php }}' + version: 9.5 + - uses: php-actions/phpstan@v3 + with: + php_version: '${{ matrix.php }}' + level: max + path: src/ diff --git a/composer.json b/composer.json index d94461c..f8b80e2 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ } }, "require": { - "php": "^7.4|^8.0|^8.1", + "php": "^7.4|^8.0", "ramsey/uuid": "^4.0", - "symfony/serializer": "^5.4|^6.0" + "symfony/serializer": "^5.4|^6.0|^7.0" }, "require-dev": { - "symfony/property-access": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0|^7.0", "phpdocumentor/reflection-docblock": "^5.3", "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^1.8" diff --git a/src/UuidDenormalizer.php b/src/UuidDenormalizer.php index 203087e..ae54dfe 100644 --- a/src/UuidDenormalizer.php +++ b/src/UuidDenormalizer.php @@ -15,15 +15,11 @@ class UuidDenormalizer implements DenormalizerInterface { /** - * {@inheritdoc} - * * @param array $context * * @throws UnexpectedValueException - * - * @return UuidInterface|null */ - public function denormalize($data, $type, $format = null, array $context = []) + public function denormalize($data, string $type, string $format = null, array $context = []): ?UuidInterface { if (null === $data) { return null; @@ -37,12 +33,20 @@ public function denormalize($data, $type, $format = null, array $context = []) } /** - * {@inheritdoc} - * * @param array $context */ - public function supportsDenormalization($data, string $type, string $format = null, array $context = []) + public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool { return Uuid::class === $type || UuidInterface::class === $type; } + + /** + * @return array + */ + public function getSupportedTypes(?string $format): array + { + return [ + UuidInterface::class => true, + ]; + } } diff --git a/src/UuidNormalizer.php b/src/UuidNormalizer.php index 9ed3aad..aa3c69b 100644 --- a/src/UuidNormalizer.php +++ b/src/UuidNormalizer.php @@ -13,25 +13,32 @@ class UuidNormalizer implements NormalizerInterface { /** - * {@inheritdoc} - * - * @param array $context - * @param UuidInterface $object - * - * @return string + * @param array $context */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, $format = null, array $context = []): string { + if (!$object instanceof UuidInterface) { + throw new \InvalidArgumentException('Expected a UuidInterface.'); + } + return $object->toString(); } /** - * {@inheritdoc} - * * @param array $context */ - public function supportsNormalization($data, $format = null, array $context = []) + public function supportsNormalization($data, $format = null, array $context = []): bool { return $data instanceof UuidInterface; } + + /** + * @return array + */ + public function getSupportedTypes(?string $format): array + { + return [ + UuidInterface::class => true, + ]; + } }