Skip to content

Commit

Permalink
Add fix for phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonKostrubiec committed Jul 9, 2024
1 parent 40caa75 commit cca61fd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/Repository/OrderItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ public function __construct(

public function countByVariant(ProductVariantInterface $variant, array $orderStates = []): int
{
if (empty($orderStates)) {
if ([] !== $orderStates) {
$orderStates = [OrderInterface::STATE_CANCELLED, OrderInterface::STATE_CART];
}

return (int) ($this->baseOrderItemRepository
/** @var EntityRepository $baseOrderItemRepository */
$baseOrderItemRepository = $this->baseOrderItemRepository;

return (int) ($baseOrderItemRepository
->createQueryBuilder('oi')
->select('SUM(oi.quantity)')
->join('oi.order', 'o')
Expand Down
7 changes: 5 additions & 2 deletions src/Repository/ProductAttributeRepository.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 Doctrine\ORM\QueryBuilder;
use Sylius\Component\Resource\Repository\RepositoryInterface;

Expand Down Expand Up @@ -39,11 +40,12 @@ 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')
->leftJoin('o.translations', 'translation', 'ot')

Check failure on line 50 in src/Repository/ProductAttributeRepository.php

View workflow job for this annotation

GitHub Actions / Sylius v1.13.3, PHP 8.1, Symfony ^6.4

Parameter #3 $conditionType of method Doctrine\ORM\QueryBuilder::leftJoin() expects 'ON'|'WITH'|null, 'ot' given.
->andWhere('translation.locale = :locale')
Expand All @@ -52,6 +54,7 @@ public function findAllWithTranslations(?string $locale): array
}

return $queryBuilder
->createQueryBuilder('o')
->getQuery()
->getResult()
;
Expand Down
10 changes: 8 additions & 2 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 Down
12 changes: 8 additions & 4 deletions src/Repository/ProductVariantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public function __construct(

public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface
{
/** @phpstan-ignore-next-line */
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 @@ -38,8 +40,10 @@ public function findOneByOptionValue(ProductOptionValueInterface $productOptionV

public function findByOptionValue(ProductOptionValueInterface $productOptionValue): array
{
/** @phpstan-ignore-next-line */
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 Down

0 comments on commit cca61fd

Please sign in to comment.