Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/Normalizer/AbsoluteDateNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

use AssoConnect\PHPDate\AbsoluteDate;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Throwable;

/**
* Normalizes an instance of {@see AbsoluteDate} to a date string.
Expand Down Expand Up @@ -40,27 +41,27 @@

/**
* {@inheritdoc}
* @param mixed[] $context
*/
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool

Check failure on line 45 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.4, lowest)

Method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::supportsNormalization() has parameter $context with no value type specified in iterable type array.

Check failure on line 45 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.3, lowest)

Method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::supportsNormalization() has parameter $context with no value type specified in iterable type array.
{
return $data instanceof AbsoluteDate;
}

/**
* {@inheritdoc}
*
* @param mixed[] $context
* @throws NotNormalizableValueException
*/
public function denormalize($data, string $type, ?string $format = null, array $context = []): ?AbsoluteDate
public function denormalize($data, string $type, ?string $format = null, array $context = []): AbsoluteDate

Check failure on line 53 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.3, highest)

Return type (AssoConnect\PHPDate\AbsoluteDate) of method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::denormalize() should be covariant with return type (($type is class-string<object> ? object : mixed)) of method Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize()

Check failure on line 53 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.4, lowest)

Method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::denormalize() has parameter $context with no value type specified in iterable type array.

Check failure on line 53 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.4, highest)

Return type (AssoConnect\PHPDate\AbsoluteDate) of method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::denormalize() should be covariant with return type (($type is class-string<object> ? object : mixed)) of method Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize()

Check failure on line 53 in src/Normalizer/AbsoluteDateNormalizer.php

View workflow job for this annotation

GitHub Actions / build (8.3, lowest)

Method AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer::denormalize() has parameter $context with no value type specified in iterable type array.
{
if ('' === $data || null === $data) {
throw new UnexpectedValueException();
}

$dateTimeFormat = $context[self::FORMAT_KEY] ?? AbsoluteDate::DEFAULT_DATE_FORMAT;

try {
return '' === $data || null === $data ? null : new AbsoluteDate($data, $dateTimeFormat);
} catch (\Exception $e) {
throw new NotNormalizableValueException($e->getMessage(), $e->getCode(), $e);
return new AbsoluteDate($data, $dateTimeFormat);
} catch (Throwable $e) {
throw new UnexpectedValueException(previous: $e);
}
}

Expand All @@ -77,11 +78,8 @@
return AbsoluteDate::class === $type;
}

/**
* @return array<'*', bool>
*/
public function getSupportedTypes(?string $format): array
{
return ['*' => false];
return [AbsoluteDate::class => true];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class AbsoluteDateValueResolver implements ValueResolverInterface
{
/**
* @return array<AbsoluteDate>
* @return list<AbsoluteDate>
*/
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
Expand Down
3 changes: 1 addition & 2 deletions tests/Normalizer/AbsoluteDateNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use AssoConnect\PHPDateBundle\Normalizer\AbsoluteDateNormalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;

class AbsoluteDateNormalizerTest extends TestCase
Expand Down Expand Up @@ -79,7 +78,7 @@ public function testDenormalizeInvalidDataThrowsException(): void

public function testDenormalizeFormatMismatchThrowsException(): void
{
$this->expectException(NotNormalizableValueException::class);
$this->expectException(UnexpectedValueException::class);
$this->normalizer->denormalize('2016/01/01', AbsoluteDate::class, null, [
AbsoluteDateNormalizer::FORMAT_KEY => 'Y-m-d|',
]);
Expand Down
Loading