From 7ae68869f76c845068e0cc1841137faa7b3fc47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Sat, 7 Dec 2024 21:06:13 +0100 Subject: [PATCH] Rename facet form builders to filter form builders because people use the word 'filters' more --- src/Document/Attribute/Facetable.php | 6 +++--- src/Document/Metadata/Facet.php | 4 ++-- ...rmBuilder.php => CheckboxFilterFormBuilder.php} | 2 +- ...FormBuilder.php => ChoiceFilterFormBuilder.php} | 6 +++--- ...mBuilder.php => CompositeFilterFormBuilder.php} | 4 ++-- ...nterface.php => FilterFormBuilderInterface.php} | 2 +- ...tFormBuilder.php => RangeFilterFormBuilder.php} | 2 +- src/Form/Builder/SearchFormBuilder.php | 6 +++--- ...terface.php => FilterValuesSorterInterface.php} | 2 +- src/Form/Builder/Sorter/SizeSorter.php | 2 +- src/Resources/config/services/form.xml | 14 +++++++------- src/SetonoSyliusMeilisearchPlugin.php | 4 ++-- 12 files changed, 27 insertions(+), 27 deletions(-) rename src/Form/Builder/{CheckboxFacetFormBuilder.php => CheckboxFilterFormBuilder.php} (93%) rename src/Form/Builder/{ChoiceFacetFormBuilder.php => ChoiceFilterFormBuilder.php} (87%) rename src/Form/Builder/{CompositeFacetFormBuilder.php => CompositeFilterFormBuilder.php} (86%) rename src/Form/Builder/{FacetFormBuilderInterface.php => FilterFormBuilderInterface.php} (96%) rename src/Form/Builder/{RangeFacetFormBuilder.php => RangeFilterFormBuilder.php} (92%) rename src/Form/Builder/Sorter/{FacetValuesSorterInterface.php => FilterValuesSorterInterface.php} (79%) diff --git a/src/Document/Attribute/Facetable.php b/src/Document/Attribute/Facetable.php index 680e92c..a931204 100644 --- a/src/Document/Attribute/Facetable.php +++ b/src/Document/Attribute/Facetable.php @@ -5,7 +5,7 @@ namespace Setono\SyliusMeilisearchPlugin\Document\Attribute; use Attribute; -use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface; +use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface; use Webmozart\Assert\Assert; #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD)] @@ -14,7 +14,7 @@ final class Facetable extends Filterable /** * TODO: Should be a service id * - * @param class-string|null $sorter + * @param class-string|null $sorter */ public function __construct(public readonly ?string $sorter = null) { @@ -22,6 +22,6 @@ public function __construct(public readonly ?string $sorter = null) return; } - Assert::true(is_a($sorter, FacetValuesSorterInterface::class, true)); + Assert::true(is_a($sorter, FilterValuesSorterInterface::class, true)); } } diff --git a/src/Document/Metadata/Facet.php b/src/Document/Metadata/Facet.php index 7618cdd..28cfdca 100644 --- a/src/Document/Metadata/Facet.php +++ b/src/Document/Metadata/Facet.php @@ -4,11 +4,11 @@ namespace Setono\SyliusMeilisearchPlugin\Document\Metadata; -use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface; +use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface; final class Facet { - /** @param class-string|null $sorter */ + /** @param class-string|null $sorter */ public function __construct( public readonly string $name, public readonly string $type, diff --git a/src/Form/Builder/CheckboxFacetFormBuilder.php b/src/Form/Builder/CheckboxFilterFormBuilder.php similarity index 93% rename from src/Form/Builder/CheckboxFacetFormBuilder.php rename to src/Form/Builder/CheckboxFilterFormBuilder.php index 4ab8517..a723d25 100644 --- a/src/Form/Builder/CheckboxFacetFormBuilder.php +++ b/src/Form/Builder/CheckboxFilterFormBuilder.php @@ -9,7 +9,7 @@ use Symfony\Component\Form\FormBuilderInterface; use function Symfony\Component\String\u; -final class CheckboxFacetFormBuilder implements FacetFormBuilderInterface +final class CheckboxFilterFormBuilder implements FilterFormBuilderInterface { public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void { diff --git a/src/Form/Builder/ChoiceFacetFormBuilder.php b/src/Form/Builder/ChoiceFilterFormBuilder.php similarity index 87% rename from src/Form/Builder/ChoiceFacetFormBuilder.php rename to src/Form/Builder/ChoiceFilterFormBuilder.php index 38b8853..14c2923 100644 --- a/src/Form/Builder/ChoiceFacetFormBuilder.php +++ b/src/Form/Builder/ChoiceFilterFormBuilder.php @@ -5,19 +5,19 @@ namespace Setono\SyliusMeilisearchPlugin\Form\Builder; use Setono\SyliusMeilisearchPlugin\Document\Metadata\Facet; -use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FacetValuesSorterInterface; +use Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\FilterValuesSorterInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use function Symfony\Component\String\u; -final class ChoiceFacetFormBuilder implements FacetFormBuilderInterface +final class ChoiceFilterFormBuilder implements FilterFormBuilderInterface { public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void { $keys = array_keys($values); $choices = array_combine($keys, $keys); - /** @var class-string $sorter */ + /** @var class-string $sorter */ $sorter = $facet->sorter; if ($facet->sorter !== null) { /** @var array $choices */ diff --git a/src/Form/Builder/CompositeFacetFormBuilder.php b/src/Form/Builder/CompositeFilterFormBuilder.php similarity index 86% rename from src/Form/Builder/CompositeFacetFormBuilder.php rename to src/Form/Builder/CompositeFilterFormBuilder.php index b79e548..f345465 100644 --- a/src/Form/Builder/CompositeFacetFormBuilder.php +++ b/src/Form/Builder/CompositeFilterFormBuilder.php @@ -9,9 +9,9 @@ use Symfony\Component\Form\FormBuilderInterface; /** - * @extends CompositeService + * @extends CompositeService */ -final class CompositeFacetFormBuilder extends CompositeService implements FacetFormBuilderInterface +final class CompositeFilterFormBuilder extends CompositeService implements FilterFormBuilderInterface { public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void { diff --git a/src/Form/Builder/FacetFormBuilderInterface.php b/src/Form/Builder/FilterFormBuilderInterface.php similarity index 96% rename from src/Form/Builder/FacetFormBuilderInterface.php rename to src/Form/Builder/FilterFormBuilderInterface.php index e75a924..716d5a9 100644 --- a/src/Form/Builder/FacetFormBuilderInterface.php +++ b/src/Form/Builder/FilterFormBuilderInterface.php @@ -7,7 +7,7 @@ use Setono\SyliusMeilisearchPlugin\Document\Metadata\Facet; use Symfony\Component\Form\FormBuilderInterface; -interface FacetFormBuilderInterface +interface FilterFormBuilderInterface { /** * @param array $values The values of the facet. This could be ['red' => 10, 'blue' => 5] where the key is the facet value and the value is the number of matching documents diff --git a/src/Form/Builder/RangeFacetFormBuilder.php b/src/Form/Builder/RangeFilterFormBuilder.php similarity index 92% rename from src/Form/Builder/RangeFacetFormBuilder.php rename to src/Form/Builder/RangeFilterFormBuilder.php index 5f76e59..97c7e71 100644 --- a/src/Form/Builder/RangeFacetFormBuilder.php +++ b/src/Form/Builder/RangeFilterFormBuilder.php @@ -9,7 +9,7 @@ use Symfony\Component\Form\FormBuilderInterface; use function Symfony\Component\String\u; -final class RangeFacetFormBuilder implements FacetFormBuilderInterface +final class RangeFilterFormBuilder implements FilterFormBuilderInterface { public function build(FormBuilderInterface $builder, Facet $facet, array $values, array $stats = null): void { diff --git a/src/Form/Builder/SearchFormBuilder.php b/src/Form/Builder/SearchFormBuilder.php index bd9dbb1..a02b2f1 100644 --- a/src/Form/Builder/SearchFormBuilder.php +++ b/src/Form/Builder/SearchFormBuilder.php @@ -18,7 +18,7 @@ final class SearchFormBuilder implements SearchFormBuilderInterface { public function __construct( private readonly FormFactoryInterface $formFactory, - private readonly FacetFormBuilderInterface $facetFormBuilder, + private readonly FilterFormBuilderInterface $filterFormBuilder, private readonly SortingFormBuilderInterface $sortingFormBuilder, private readonly MetadataFactoryInterface $metadataFactory, private readonly Index $index, @@ -113,8 +113,8 @@ public function build(SearchResult $searchResult): FormInterface continue; } - if ($this->facetFormBuilder->supports($facets[$name], $values, $facetStats[$name] ?? null)) { - $this->facetFormBuilder->build($facetsFormBuilder, $facets[$name], $values, $facetStats[$name] ?? null); + if ($this->filterFormBuilder->supports($facets[$name], $values, $facetStats[$name] ?? null)) { + $this->filterFormBuilder->build($facetsFormBuilder, $facets[$name], $values, $facetStats[$name] ?? null); } } diff --git a/src/Form/Builder/Sorter/FacetValuesSorterInterface.php b/src/Form/Builder/Sorter/FilterValuesSorterInterface.php similarity index 79% rename from src/Form/Builder/Sorter/FacetValuesSorterInterface.php rename to src/Form/Builder/Sorter/FilterValuesSorterInterface.php index d719430..c6c28ad 100644 --- a/src/Form/Builder/Sorter/FacetValuesSorterInterface.php +++ b/src/Form/Builder/Sorter/FilterValuesSorterInterface.php @@ -4,7 +4,7 @@ namespace Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter; -interface FacetValuesSorterInterface +interface FilterValuesSorterInterface { public function sort(array $values): array; } diff --git a/src/Form/Builder/Sorter/SizeSorter.php b/src/Form/Builder/Sorter/SizeSorter.php index 3ed7e64..1340edc 100644 --- a/src/Form/Builder/Sorter/SizeSorter.php +++ b/src/Form/Builder/Sorter/SizeSorter.php @@ -6,7 +6,7 @@ use DragonCode\SizeSorter\Sorter; -final class SizeSorter implements FacetValuesSorterInterface +final class SizeSorter implements FilterValuesSorterInterface { public function sort(array $values): array { diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index d14f447..5671364 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -8,20 +8,20 @@ - + - + - + - + - + @@ -37,7 +37,7 @@ - + diff --git a/src/SetonoSyliusMeilisearchPlugin.php b/src/SetonoSyliusMeilisearchPlugin.php index 5826825..6368dab 100644 --- a/src/SetonoSyliusMeilisearchPlugin.php +++ b/src/SetonoSyliusMeilisearchPlugin.php @@ -7,7 +7,7 @@ use Setono\CompositeCompilerPass\CompositeCompilerPass; use Setono\SyliusMeilisearchPlugin\DataMapper\CompositeDataMapper; use Setono\SyliusMeilisearchPlugin\Filter\Entity\CompositeEntityFilter; -use Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder; +use Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder; use Setono\SyliusMeilisearchPlugin\Meilisearch\Filter\CompositeFilterBuilder; use Setono\SyliusMeilisearchPlugin\Provider\IndexScope\CompositeIndexScopeProvider; use Setono\SyliusMeilisearchPlugin\Provider\Settings\CompositeSettingsProvider; @@ -33,7 +33,7 @@ public function build(ContainerBuilder $container): void // Register services in composite services $container->addCompilerPass(new CompositeCompilerPass( - CompositeFacetFormBuilder::class, + CompositeFilterFormBuilder::class, 'setono_sylius_meilisearch.facet_form_builder', ));