diff --git a/composer.json b/composer.json index 5a9a31b..3fca2a5 100644 --- a/composer.json +++ b/composer.json @@ -24,19 +24,19 @@ "php": " >=8.3", "ibexa/core": "~5.0.x-dev", "pagerfanta/pagerfanta": "^3.6.2", - "symfony/config": "^6.4", - "symfony/dependency-injection": "^6.4", - "symfony/event-dispatcher": "^6.4", - "symfony/form": "^6.4", - "symfony/http-foundation": "^6.4", - "symfony/http-kernel": "^6.4", - "symfony/serializer": "^6.4" + "symfony/config": "^7.2", + "symfony/dependency-injection": "^7.2", + "symfony/event-dispatcher": "^7.2", + "symfony/form": "^7.2", + "symfony/http-foundation": "^7.2", + "symfony/http-kernel": "^7.2", + "symfony/serializer": "^7.2" }, "require-dev": { "ibexa/code-style": "~2.0.0", "ibexa/doctrine-schema": "~5.0.x-dev", "ibexa/rector": "~5.0.x-dev", - "matthiasnoback/symfony-dependency-injection-test": "^4.3", + "matthiasnoback/symfony-dependency-injection-test": "^5.0", "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 78268ab..3ad7e3e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -150,24 +150,6 @@ parameters: count: 1 path: src/bundle/Form/DataTransformer/DateIntervalTransformer.php - - - message: '#^Class Ibexa\\Bundle\\Search\\Form\\DataTransformer\\UserTransformer implements generic interface Symfony\\Component\\Form\\DataTransformerInterface but does not specify its types\: T, R$#' - identifier: missingType.generics - count: 1 - path: src/bundle/Form/DataTransformer/UserTransformer.php - - - - message: '#^Instanceof between Ibexa\\Contracts\\Core\\Repository\\Values\\User\\User and Ibexa\\Contracts\\Core\\Repository\\Values\\User\\User will always evaluate to true\.$#' - identifier: instanceof.alwaysTrue - count: 1 - path: src/bundle/Form/DataTransformer/UserTransformer.php - - - - message: '#^Method Ibexa\\Bundle\\Search\\Form\\DataTransformer\\UserTransformer\:\:transform\(\) has Symfony\\Component\\Form\\Exception\\TransformationFailedException in PHPDoc @throws tag but it''s not thrown\.$#' - identifier: throws.unusedType - count: 1 - path: src/bundle/Form/DataTransformer/UserTransformer.php - - message: '#^Class Ibexa\\Bundle\\Search\\Form\\DataTransformer\\UsersTransformer implements generic interface Symfony\\Component\\Form\\DataTransformerInterface but does not specify its types\: T, R$#' identifier: missingType.generics diff --git a/src/bundle/Form/DataTransformer/DateIntervalTransformer.php b/src/bundle/Form/DataTransformer/DateIntervalTransformer.php index 541f668..8516697 100644 --- a/src/bundle/Form/DataTransformer/DateIntervalTransformer.php +++ b/src/bundle/Form/DataTransformer/DateIntervalTransformer.php @@ -23,7 +23,7 @@ class DateIntervalTransformer implements DataTransformerInterface * * @throws \Symfony\Component\Form\Exception\TransformationFailedException */ - public function transform($value) + public function transform(mixed $value): ?array { return null; } @@ -38,7 +38,7 @@ public function transform($value) * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function reverseTransform($value) + public function reverseTransform(mixed $value): ?array { if (null === $value || !\is_array($value)) { return []; diff --git a/src/bundle/Form/DataTransformer/UserTransformer.php b/src/bundle/Form/DataTransformer/UserTransformer.php index 26a41b8..66d5788 100644 --- a/src/bundle/Form/DataTransformer/UserTransformer.php +++ b/src/bundle/Form/DataTransformer/UserTransformer.php @@ -16,6 +16,8 @@ /** * Transforms between a User's ID and a domain specific User object. + * + * @phpstan-implements \Symfony\Component\Form\DataTransformerInterface */ class UserTransformer implements DataTransformerInterface { @@ -31,47 +33,25 @@ public function __construct(UserService $userService) /** * Transforms a domain specific User object into a Users's ID. - * - * @param \Ibexa\Contracts\Core\Repository\Values\User\User|null $value - * - * @return mixed|null - * - * @throws \Symfony\Component\Form\Exception\TransformationFailedException */ - public function transform($value) + public function transform(mixed $value): ?int { if (null === $value) { return null; } - if (!$value instanceof User) { - throw new TransformationFailedException('Expected a ' . User::class . ' object.'); - } - return $value->id; } /** * Transforms a Users's ID integer into a domain specific User object. - * - * @param mixed|null $value - * - * @return \Ibexa\Contracts\Core\Repository\Values\User\User|null - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException - * @throws \Symfony\Component\Form\Exception\TransformationFailedException if the given value is not an integer - * or if the value can not be transformed */ - public function reverseTransform($value): ?User + public function reverseTransform(mixed $value): ?User { if (empty($value)) { return null; } - if (!is_numeric($value)) { - throw new TransformationFailedException('Expected a numeric string.'); - } - try { return $this->userService->loadUser((int)$value); } catch (NotFoundException $e) { diff --git a/src/bundle/Form/DataTransformer/UsersTransformer.php b/src/bundle/Form/DataTransformer/UsersTransformer.php index 2b2432b..133390a 100644 --- a/src/bundle/Form/DataTransformer/UsersTransformer.php +++ b/src/bundle/Form/DataTransformer/UsersTransformer.php @@ -47,7 +47,7 @@ public function __construct( * * @throws \Symfony\Component\Form\Exception\TransformationFailedException */ - public function transform($value): ?string + public function transform(mixed $value): ?string { if (null === $value) { return null; @@ -63,7 +63,7 @@ public function transform($value): ?string /** * @param string|null $value */ - public function reverseTransform($value): SearchUsersData + public function reverseTransform(mixed $value): SearchUsersData { if ($value === null) { return new SearchUsersData(); diff --git a/src/bundle/Twig/Extension/SearchFacetsExtension.php b/src/bundle/Twig/Extension/SearchFacetsExtension.php index 17d5426..ec27714 100644 --- a/src/bundle/Twig/Extension/SearchFacetsExtension.php +++ b/src/bundle/Twig/Extension/SearchFacetsExtension.php @@ -14,11 +14,18 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Search\AggregationResult\TermAggregationResultEntry; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; +use Symfony\Contracts\Translation\TranslatableInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; final class SearchFacetsExtension extends AbstractExtension { + public function __construct( + private readonly TranslatorInterface $translator, + ) { + } + public function getFilters(): array { return [ @@ -64,8 +71,13 @@ public function getChoicesAsFacets( $term = $this->findTermEntry($terms, $choice, $comparator); if ($term !== null) { + $label = $choice->label; + if ($label instanceof TranslatableInterface) { + $label = $label->trans($this->translator); + } + $facet = FacetView::createFromChoiceView($choice, $term); - $facet->label = sprintf('%s (%d)', $choice->label, $term->getCount()); + $facet->label = sprintf('%s (%d)', $label, $term->getCount()); $facets[$key] = $facet; } } diff --git a/src/lib/Serializer/Normalizer/Suggestion/ContentSuggestionNormalizer.php b/src/lib/Serializer/Normalizer/Suggestion/ContentSuggestionNormalizer.php index cba0d07..8f6b749 100644 --- a/src/lib/Serializer/Normalizer/Suggestion/ContentSuggestionNormalizer.php +++ b/src/lib/Serializer/Normalizer/Suggestion/ContentSuggestionNormalizer.php @@ -9,15 +9,13 @@ namespace Ibexa\Search\Serializer\Normalizer\Suggestion; use Ibexa\Contracts\Search\Model\Suggestion\ContentSuggestion; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; final class ContentSuggestionNormalizer implements NormalizerInterface, - NormalizerAwareInterface, - CacheableSupportsMethodInterface + NormalizerAwareInterface { use NormalizerAwareTrait; @@ -26,7 +24,7 @@ final class ContentSuggestionNormalizer implements * * @return array */ - public function normalize($object, string $format = null, array $context = []): array + public function normalize(mixed $object, string $format = null, array $context = []): array { $content = $object->getContent(); @@ -41,13 +39,15 @@ public function normalize($object, string $format = null, array $context = []): ]; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ContentSuggestion; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format): array { - return true; + return [ + ContentSuggestion::class => true, + ]; } } diff --git a/src/lib/Serializer/Normalizer/Suggestion/LocationNormalizer.php b/src/lib/Serializer/Normalizer/Suggestion/LocationNormalizer.php index f30960f..3a36618 100644 --- a/src/lib/Serializer/Normalizer/Suggestion/LocationNormalizer.php +++ b/src/lib/Serializer/Normalizer/Suggestion/LocationNormalizer.php @@ -18,7 +18,7 @@ final class LocationNormalizer implements NormalizerInterface * * @return array */ - public function normalize($object, string $format = null, array $context = []): array + public function normalize(mixed $object, string $format = null, array $context = []): array { return [ 'id' => $object->getContentInfo()->getId(), @@ -27,13 +27,15 @@ public function normalize($object, string $format = null, array $context = []): ]; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof Location; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format): array { - return true; + return [ + Location::class => true, + ]; } } diff --git a/src/lib/Serializer/Normalizer/Suggestion/ParentLocationCollectionNormalizer.php b/src/lib/Serializer/Normalizer/Suggestion/ParentLocationCollectionNormalizer.php index 8e2a975..c1a5139 100644 --- a/src/lib/Serializer/Normalizer/Suggestion/ParentLocationCollectionNormalizer.php +++ b/src/lib/Serializer/Normalizer/Suggestion/ParentLocationCollectionNormalizer.php @@ -9,15 +9,13 @@ namespace Ibexa\Search\Serializer\Normalizer\Suggestion; use Ibexa\Contracts\Search\Model\Suggestion\ParentLocationCollection; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; final class ParentLocationCollectionNormalizer implements NormalizerInterface, - NormalizerAwareInterface, - CacheableSupportsMethodInterface + NormalizerAwareInterface { use NormalizerAwareTrait; @@ -27,7 +25,7 @@ final class ParentLocationCollectionNormalizer implements * * @return array. */ - public function normalize($object, string $format = null, array $context = []): array + public function normalize(mixed $object, string $format = null, array $context = []): array { $normalizedData = []; @@ -38,13 +36,15 @@ public function normalize($object, string $format = null, array $context = []): return $normalizedData; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof ParentLocationCollection; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format): array { - return true; + return [ + ParentLocationCollection::class => true, + ]; } } diff --git a/src/lib/Serializer/Normalizer/Suggestion/SuggestionCollectionNormalizer.php b/src/lib/Serializer/Normalizer/Suggestion/SuggestionCollectionNormalizer.php index 55a28b2..8420d2c 100644 --- a/src/lib/Serializer/Normalizer/Suggestion/SuggestionCollectionNormalizer.php +++ b/src/lib/Serializer/Normalizer/Suggestion/SuggestionCollectionNormalizer.php @@ -9,15 +9,13 @@ namespace Ibexa\Search\Serializer\Normalizer\Suggestion; use Ibexa\Contracts\Search\Model\Suggestion\SuggestionCollection; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; final class SuggestionCollectionNormalizer implements NormalizerInterface, - NormalizerAwareInterface, - CacheableSupportsMethodInterface + NormalizerAwareInterface { use NormalizerAwareTrait; @@ -27,7 +25,7 @@ final class SuggestionCollectionNormalizer implements * * @return array. */ - public function normalize($object, string $format = null, array $context = []): array + public function normalize(mixed $object, string $format = null, array $context = []): array { $suggestionCollection = []; @@ -41,13 +39,15 @@ public function normalize($object, string $format = null, array $context = []): ]; } - public function supportsNormalization($data, string $format = null): bool + public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool { return $data instanceof SuggestionCollection; } - public function hasCacheableSupportsMethod(): bool + public function getSupportedTypes(?string $format): array { - return true; + return [ + SuggestionCollection::class => true, + ]; } }