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
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 0 additions & 18 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Form/DataTransformer/DateIntervalTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 [];
Expand Down
28 changes: 4 additions & 24 deletions src/bundle/Form/DataTransformer/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

/**
* Transforms between a User's ID and a domain specific User object.
*
* @phpstan-implements \Symfony\Component\Form\DataTransformerInterface<User, int>
*/
class UserTransformer implements DataTransformerInterface
{
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Form/DataTransformer/UsersTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/bundle/Twig/Extension/SearchFacetsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,7 +24,7 @@ final class ContentSuggestionNormalizer implements
*
* @return array<string, mixed>
*/
public function normalize($object, string $format = null, array $context = []): array
public function normalize(mixed $object, string $format = null, array $context = []): array
{
$content = $object->getContent();

Expand All @@ -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,
];
}
}
10 changes: 6 additions & 4 deletions src/lib/Serializer/Normalizer/Suggestion/LocationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LocationNormalizer implements NormalizerInterface
*
* @return array<string, mixed>
*/
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(),
Expand All @@ -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,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,7 +25,7 @@ final class ParentLocationCollectionNormalizer implements
*
* @return array<int,mixed>.
*/
public function normalize($object, string $format = null, array $context = []): array
public function normalize(mixed $object, string $format = null, array $context = []): array
{
$normalizedData = [];

Expand All @@ -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,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,7 +25,7 @@ final class SuggestionCollectionNormalizer implements
*
* @return array<string,mixed>.
*/
public function normalize($object, string $format = null, array $context = []): array
public function normalize(mixed $object, string $format = null, array $context = []): array
{
$suggestionCollection = [];

Expand All @@ -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,
];
}
}
Loading