Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename facet form builders to filter form builders because people use the word 'filters' more #43

Merged
merged 1 commit into from
Dec 7, 2024
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
6 changes: 3 additions & 3 deletions src/Document/Attribute/Facetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -14,14 +14,14 @@
/**
* TODO: Should be a service id
*
* @param class-string<FacetValuesSorterInterface>|null $sorter
* @param class-string<FilterValuesSorterInterface>|null $sorter
*/
public function __construct(public readonly ?string $sorter = null)
{
if ($this->sorter === null) {
return;
}

Assert::true(is_a($sorter, FacetValuesSorterInterface::class, true));
Assert::true(is_a($sorter, FilterValuesSorterInterface::class, true));

Check warning on line 25 in src/Document/Attribute/Facetable.php

View check run for this annotation

Codecov / codecov/patch

src/Document/Attribute/Facetable.php#L25

Added line #L25 was not covered by tests
}
}
4 changes: 2 additions & 2 deletions src/Document/Metadata/Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<FacetValuesSorterInterface>|null $sorter */
/** @param class-string<FilterValuesSorterInterface>|null $sorter */
public function __construct(
public readonly string $name,
public readonly string $type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FacetValuesSorterInterface> $sorter */
/** @var class-string<FilterValuesSorterInterface> $sorter */
$sorter = $facet->sorter;
if ($facet->sorter !== null) {
/** @var array $choices */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Symfony\Component\Form\FormBuilderInterface;

/**
* @extends CompositeService<FacetFormBuilderInterface>
* @extends CompositeService<FilterFormBuilderInterface>
*/
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Setono\SyliusMeilisearchPlugin\Document\Metadata\Facet;
use Symfony\Component\Form\FormBuilderInterface;

interface FacetFormBuilderInterface
interface FilterFormBuilderInterface
{
/**
* @param array<string, int> $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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Builder/SearchFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

final class SearchFormBuilder implements SearchFormBuilderInterface
{
public function __construct(

Check failure on line 19 in src/Form/Builder/SearchFormBuilder.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

The parameter $facetFormBuilder of Setono\SyliusMeilisearchPlugin\Form\Builder\SearchFormBuilder#__construct() changed from Setono\SyliusMeilisearchPlugin\Form\Builder\FacetFormBuilderInterface to a non-contravariant Setono\SyliusMeilisearchPlugin\Form\Builder\FilterFormBuilderInterface
private readonly FormFactoryInterface $formFactory,
private readonly FacetFormBuilderInterface $facetFormBuilder,
private readonly FilterFormBuilderInterface $filterFormBuilder,
private readonly SortingFormBuilderInterface $sortingFormBuilder,
private readonly MetadataFactoryInterface $metadataFactory,
private readonly Index $index,
Expand Down Expand Up @@ -113,8 +113,8 @@
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);

Check warning on line 117 in src/Form/Builder/SearchFormBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/Form/Builder/SearchFormBuilder.php#L116-L117

Added lines #L116 - L117 were not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter;

interface FacetValuesSorterInterface
interface FilterValuesSorterInterface
{
public function sort(array $values): array;
}
2 changes: 1 addition & 1 deletion src/Form/Builder/Sorter/SizeSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use DragonCode\SizeSorter\Sorter;

final class SizeSorter implements FacetValuesSorterInterface
final class SizeSorter implements FilterValuesSorterInterface

Check failure on line 9 in src/Form/Builder/Sorter/SizeSorter.php

View workflow job for this annotation

GitHub Actions / Backwards Compatibility Check

These ancestors of Setono\SyliusMeilisearchPlugin\Form\Builder\Sorter\SizeSorter have been removed: ["Setono\\SyliusMeilisearchPlugin\\Form\\Builder\\Sorter\\FacetValuesSorterInterface"]
{
public function sort(array $values): array
{
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
</parameters>
<services>
<!-- Facet form builders -->
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\FacetFormBuilderInterface"
alias="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder"/>
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\FilterFormBuilderInterface"
alias="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder"/>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFacetFormBuilder"/>
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CompositeFilterFormBuilder"/>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CheckboxFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\CheckboxFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="100"/>
</service>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\ChoiceFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\ChoiceFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="90"/>
</service>

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\RangeFacetFormBuilder">
<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\RangeFilterFormBuilder">
<tag name="setono_sylius_meilisearch.facet_form_builder" priority="80"/>
</service>

Expand All @@ -37,7 +37,7 @@

<service id="Setono\SyliusMeilisearchPlugin\Form\Builder\SearchFormBuilder">
<argument type="service" id="form.factory"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\FacetFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\FilterFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Form\Builder\SortingFormBuilderInterface"/>
<argument type="service" id="Setono\SyliusMeilisearchPlugin\Document\Metadata\MetadataFactoryInterface"/>
<argument type="service" id="setono_sylius_meilisearch.index.search"/>
Expand Down
4 changes: 2 additions & 2 deletions src/SetonoSyliusMeilisearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +33,7 @@

// Register services in composite services
$container->addCompilerPass(new CompositeCompilerPass(
CompositeFacetFormBuilder::class,
CompositeFilterFormBuilder::class,

Check warning on line 36 in src/SetonoSyliusMeilisearchPlugin.php

View check run for this annotation

Codecov / codecov/patch

src/SetonoSyliusMeilisearchPlugin.php#L36

Added line #L36 was not covered by tests
'setono_sylius_meilisearch.facet_form_builder',
));

Expand Down
Loading