diff --git a/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php b/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php index 81921303..856d0f24 100644 --- a/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php +++ b/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php @@ -12,11 +12,9 @@ namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder; use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface; -use BitBag\SyliusElasticsearchPlugin\Model\Search; use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface; use Elastica\Query; use Symfony\Component\Form\FormEvent; -use Webmozart\Assert\Assert; final class SiteWideFacetsQueryBuilder implements SiteWideFacetsQueryBuilderInterface { @@ -28,18 +26,15 @@ public function __construct( public function getQuery(FormEvent $event): Query { - /** @var Search $data */ + /** @var array $data */ $data = $event->getData(); - $box = $data->getBox(); - - Assert::notNull($box); /** @var Query\BoolQuery $boolQuery */ $boolQuery = $this->queryBuilder->buildQuery([ - 'query' => $box->getQuery() ?? '', + 'query' => $data['box']['query'] ?? '', ]); - foreach ($data->getFacets() as $facetId => $selectedBuckets) { + foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) { if (!$selectedBuckets) { continue; } diff --git a/src/Repository/OrderItemRepository.php b/src/Repository/OrderItemRepository.php index 6c263411..40c22e43 100644 --- a/src/Repository/OrderItemRepository.php +++ b/src/Repository/OrderItemRepository.php @@ -25,7 +25,7 @@ public function __construct( public function countByVariant(ProductVariantInterface $variant, array $orderStates = []): int { - if ([] === $orderStates) { + if ([] !== $orderStates) { $orderStates = [OrderInterface::STATE_CANCELLED, OrderInterface::STATE_CART]; } diff --git a/src/Repository/ProductAttributeRepository.php b/src/Repository/ProductAttributeRepository.php index b8656a3b..10f4f56c 100644 --- a/src/Repository/ProductAttributeRepository.php +++ b/src/Repository/ProductAttributeRepository.php @@ -18,18 +18,17 @@ class ProductAttributeRepository implements ProductAttributeRepositoryInterface { public function __construct( - private RepositoryInterface|EntityRepository $productAttributeRepository + private RepositoryInterface $productAttributeRepository ) { } public function getAttributeTypeByName(string $attributeName): string { - /** @var EntityRepository $productAttributeRepository */ - $productAttributeRepository = $this->productAttributeRepository; - - $queryBuilder = $productAttributeRepository->createQueryBuilder('p'); + /** @var EntityRepository $queryBuilder */ + $queryBuilder = $this->productAttributeRepository; $result = $queryBuilder + ->createQueryBuilder('p') ->select('p.type') ->where('p.code = :code') ->setParameter(':code', $attributeName) @@ -44,12 +43,13 @@ public function findAllWithTranslations(?string $locale): array /** @var EntityRepository $productAttributeRepository */ $productAttributeRepository = $this->productAttributeRepository; - $queryBuilder = $productAttributeRepository->createQueryBuilder('p'); + $queryBuilder = $productAttributeRepository->createQueryBuilder('o'); if (null !== $locale) { $queryBuilder ->addSelect('translation') - ->leftJoin('o.translations', 'ot') + /** @phpstan-ignore-next-line phpstan can't read relationship correctly */ + ->leftJoin('o.translations', 'translation', 'ot') ->andWhere('translation.locale = :locale') ->setParameter('locale', $locale) ; diff --git a/src/Repository/ProductAttributeValueRepository.php b/src/Repository/ProductAttributeValueRepository.php index 8cf3d53d..e109ec5a 100644 --- a/src/Repository/ProductAttributeValueRepository.php +++ b/src/Repository/ProductAttributeValueRepository.php @@ -20,7 +20,7 @@ class ProductAttributeValueRepository implements ProductAttributeValueRepositoryInterface { public function __construct( - private BaseAttributeValueRepositoryInterface|EntityRepository $baseAttributeValueRepository, + private BaseAttributeValueRepositoryInterface $baseAttributeValueRepository, private bool $includeAllDescendants ) { } diff --git a/src/Repository/ProductOptionRepository.php b/src/Repository/ProductOptionRepository.php index 4f83c075..07af6300 100644 --- a/src/Repository/ProductOptionRepository.php +++ b/src/Repository/ProductOptionRepository.php @@ -18,27 +18,28 @@ class ProductOptionRepository implements ProductOptionRepositoryInterface { public function __construct( - private RepositoryInterface|EntityRepository $productOptionRepository + private RepositoryInterface $productOptionRepository ) { } public function findAllWithTranslations(?string $locale): array { - /** @var EntityRepository $productOptionRepository */ - $productOptionRepository = $this->productOptionRepository; - - $queryBuilder = $productOptionRepository->createQueryBuilder('o'); + /** @var EntityRepository $queryBuilder */ + $queryBuilder = $this->productOptionRepository; if (null !== $locale) { $queryBuilder + ->createQueryBuilder('o') ->addSelect('translation') - ->leftJoin('o.translations', 'ot') + /** @phpstan-ignore-next-line phpstan can't read relationship correctly */ + ->leftJoin('o.translations', 'translation', 'ot') ->andWhere('translation.locale = :locale') ->setParameter('locale', $locale) ; } return $queryBuilder + ->createQueryBuilder('o') ->getQuery() ->getResult() ; diff --git a/src/Repository/ProductVariantRepository.php b/src/Repository/ProductVariantRepository.php index e84fc109..bb305806 100644 --- a/src/Repository/ProductVariantRepository.php +++ b/src/Repository/ProductVariantRepository.php @@ -29,7 +29,8 @@ public function findOneByOptionValue(ProductOptionValueInterface $productOptionV /** @var EntityRepository $baseProductVariantRepository */ $baseProductVariantRepository = $this->baseProductVariantRepository; - return $baseProductVariantRepository->createQueryBuilder('o') + return $baseProductVariantRepository + ->createQueryBuilder('o') ->where(':optionValue MEMBER OF o.optionValues') ->setParameter('optionValue', $productOptionValue) ->getQuery() @@ -43,7 +44,8 @@ public function findByOptionValue(ProductOptionValueInterface $productOptionValu /** @var EntityRepository $baseProductVariantRepository */ $baseProductVariantRepository = $this->baseProductVariantRepository; - return $baseProductVariantRepository->createQueryBuilder('o') + return $baseProductVariantRepository + ->createQueryBuilder('o') ->where(':optionValue MEMBER OF o.optionValues') ->setParameter('optionValue', $productOptionValue) ->getQuery() diff --git a/src/Repository/TaxonRepository.php b/src/Repository/TaxonRepository.php index 76f9a0f2..b0208e0c 100644 --- a/src/Repository/TaxonRepository.php +++ b/src/Repository/TaxonRepository.php @@ -43,7 +43,8 @@ public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): a ->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id') ->where( 'pt.product IN(' . - $productRepository->createQueryBuilder('p') + $productRepository + ->createQueryBuilder('p') ->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id') ->where('pav.attribute = :attribute') ->getQuery()