Skip to content

Commit

Permalink
op-352 - Added fix for phpStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Kostrubiec committed Jul 9, 2024
1 parent a82f7e1 commit d80436e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ public function getQuery(FormEvent $event): Query
/** @var Search $data */
$data = $event->getData();

/** @var Query\BoolQuery $boolQuery */
$boolQuery = $this->queryBuilder->buildQuery([
/** @phpstan-ignore-next-line */
'query' => $data['box']['query'] ?? '',
]);

/** @phpstan-ignore-next-line */
foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) {
if (!$selectedBuckets) {
continue;
Expand All @@ -45,4 +48,4 @@ public function getQuery(FormEvent $event): Query

return new Query($boolQuery);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function getQuery(FormEvent $event, string $namePropertyPrefix): Query

$data = $this->shopProductListDataHandler->retrieveData($eventData);

/** @var Query\BoolQuery $boolQuery */
$boolQuery = $this->searchProductsQueryBuilder->buildQuery($data);

foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) {
Expand All @@ -47,4 +48,4 @@ public function getQuery(FormEvent $event, string $namePropertyPrefix): Query

return new Query($boolQuery);
}
}
}
8 changes: 5 additions & 3 deletions src/Repository/OrderItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public function __construct(

public function countByVariant(ProductVariantInterface $variant, array $orderStates = []): int
{
if (empty($orderStates)) {
if ([] !== $orderStates) {
$orderStates = [OrderInterface::STATE_CANCELLED, OrderInterface::STATE_CART];
}
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->baseOrderItemRepository;

return (int) ($this->baseOrderItemRepository
return (int) ($queryBuilder
->createQueryBuilder('oi')
->select('SUM(oi.quantity)')
->join('oi.order', 'o')
Expand All @@ -40,4 +42,4 @@ public function countByVariant(ProductVariantInterface $variant, array $orderSta
->getQuery()
->getSingleScalarResult());
}
}
}
16 changes: 10 additions & 6 deletions src/Repository/ProductAttributeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace BitBag\SyliusElasticsearchPlugin\Repository;

use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Repository\RepositoryInterface;

class ProductAttributeRepository implements ProductAttributeRepositoryInterface
Expand All @@ -24,10 +24,11 @@ public function __construct(

public function getAttributeTypeByName(string $attributeName): string
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->productAttributeRepository->createQueryBuilder('p');
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productAttributeRepository;

$result = $queryBuilder
->createQueryBuilder('p')
->select('p.type')
->where('p.code = :code')
->setParameter(':code', $attributeName)
Expand All @@ -39,21 +40,24 @@ public function getAttributeTypeByName(string $attributeName): string

public function findAllWithTranslations(?string $locale): array
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->productAttributeRepository->createQueryBuilder('o');
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productAttributeRepository;

if (null !== $locale) {
$queryBuilder
->createQueryBuilder('o')
->addSelect('translation')
/** @phpstan-ignore-next-line */
->leftJoin('o.translations', 'translation', 'ot')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
;
}

return $queryBuilder
->createQueryBuilder('o')
->getQuery()
->getResult()
;
}
}
}
12 changes: 9 additions & 3 deletions src/Repository/ProductAttributeValueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace BitBag\SyliusElasticsearchPlugin\Repository;

use Doctrine\ORM\EntityRepository;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface as BaseAttributeValueRepositoryInterface;
use Sylius\Component\Taxonomy\Model\Taxon;
Expand All @@ -26,26 +27,31 @@ public function __construct(

public function getUniqueAttributeValues(AttributeInterface $productAttribute, Taxon $taxon): array
{
$queryBuilder = $this->baseAttributeValueRepository->createQueryBuilder('o');
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->baseAttributeValueRepository;

/** @var string|null $storageType */
$storageType = $productAttribute->getStorageType();

$queryBuilder
->createQueryBuilder('o')
->join('o.subject', 'p', 'WITH', 'p.enabled = 1')
->join('p.productTaxons', 't', 'WITH', 't.product = p.id')
->select('o.localeCode, o.' . $storageType . ' as value')
->andWhere('t.taxon = :taxon');

if (true === $this->includeAllDescendants) {
$queryBuilder->innerJoin('t.taxon', 'taxon')
$queryBuilder
->createQueryBuilder('o')
->innerJoin('t.taxon', 'taxon')
->orWhere('taxon.left >= :taxonLeft and taxon.right <= :taxonRight and taxon.root = :taxonRoot')
->setParameter('taxonLeft', $taxon->getLeft())
->setParameter('taxonRight', $taxon->getRight())
->setParameter('taxonRoot', $taxon->getRoot());
}

return $queryBuilder
->createQueryBuilder('o')
->andWhere('o.attribute = :attribute')
->groupBy('o.' . $storageType)
->addGroupBy('o.localeCode')
Expand All @@ -55,4 +61,4 @@ public function getUniqueAttributeValues(AttributeInterface $productAttribute, T
->getResult()
;
}
}
}
11 changes: 7 additions & 4 deletions src/Repository/ProductOptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace BitBag\SyliusElasticsearchPlugin\Repository;

use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Repository\RepositoryInterface;

class ProductOptionRepository implements ProductOptionRepositoryInterface
Expand All @@ -24,21 +24,24 @@ public function __construct(

public function findAllWithTranslations(?string $locale): array
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->productOptionRepository->createQueryBuilder('o');
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productOptionRepository;

if (null !== $locale) {
$queryBuilder
->createQueryBuilder('o')
->addSelect('translation')
/** @phpstan-ignore-next-line */
->leftJoin('o.translations', 'translation', 'ot')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
;
}

return $queryBuilder
->createQueryBuilder('o')
->getQuery()
->getResult()
;
}
}
}
12 changes: 9 additions & 3 deletions src/Repository/ProductVariantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public function __construct(

public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface
{
return $this->baseProductVariantRepository->createQueryBuilder('o')
/** @var EntityRepository $baseProductVariantRepository */
$baseProductVariantRepository = $this->baseProductVariantRepository;

return $baseProductVariantRepository->createQueryBuilder('o')
->where(':optionValue MEMBER OF o.optionValues')
->setParameter('optionValue', $productOptionValue)
->getQuery()
Expand All @@ -37,11 +40,14 @@ public function findOneByOptionValue(ProductOptionValueInterface $productOptionV

public function findByOptionValue(ProductOptionValueInterface $productOptionValue): array
{
return $this->baseProductVariantRepository->createQueryBuilder('o')
/** @var EntityRepository $baseProductVariantRepository */
$baseProductVariantRepository = $this->baseProductVariantRepository;

return $baseProductVariantRepository->createQueryBuilder('o')
->where(':optionValue MEMBER OF o.optionValues')
->setParameter('optionValue', $productOptionValue)
->getQuery()
->getResult()
;
}
}
}
14 changes: 10 additions & 4 deletions src/Repository/TaxonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ public function __construct(

public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array
{
return $this->baseTaxonRepository
/** @var EntityRepository $baseTaxonRepository */
$baseTaxonRepository = $this->baseTaxonRepository;

/** @var EntityRepository $productRepository */
$productRepository = $this->productRepository;

return $baseTaxonRepository
->createQueryBuilder('t')
->distinct(true)
->select('t')
->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id')
->where(
'pt.product IN(' .
$this
->productRepository->createQueryBuilder('p')
$productRepository
->createQueryBuilder('p')
->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id')
->where('pav.attribute = :attribute')
->getQuery()
Expand All @@ -50,4 +56,4 @@ public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): a
->getResult()
;
}
}
}

0 comments on commit d80436e

Please sign in to comment.