ProductVariantRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findOneByOptionValue() 0 8 1
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusElasticsearchPlugin\Repository;
12
13
use Doctrine\ORM\EntityRepository;
14
use Sylius\Component\Core\Model\ProductVariantInterface;
15
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface as BaseProductVariantRepositoryInterface;
16
use Sylius\Component\Product\Model\ProductOptionValueInterface;
17
18
class ProductVariantRepository implements ProductVariantRepositoryInterface
19
{
20
    /** @var BaseProductVariantRepositoryInterface|EntityRepository */
21
    private $baseProductVariantRepository;
22
23
    public function __construct(BaseProductVariantRepositoryInterface $baseProductVariantRepository)
24
    {
25
        $this->baseProductVariantRepository = $baseProductVariantRepository;
26
    }
27
28
    public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface
29
    {
30
        return $this->baseProductVariantRepository->createQueryBuilder('o')
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on Sylius\Component\Core\Re...iantRepositoryInterface. Did you maybe mean createQueryBuilderByProductId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $this->baseProductVariantRepository->/** @scrutinizer ignore-call */ createQueryBuilder('o')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The expression return $this->baseProduc...)->getOneOrNullResult() could return the type integer which is incompatible with the type-hinted return Sylius\Component\Core\Mo...ctVariantInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
31
            ->where(':optionValue MEMBER OF o.optionValues')
32
            ->setParameter('optionValue', $productOptionValue)
33
            ->getQuery()
34
            ->setMaxResults(1)
35
            ->getOneOrNullResult()
36
        ;
37
    }
38
}
39