Passed
Pull Request — master (#148)
by Mateusz
07:58
created

OrderItemRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A countByVariant() 0 9 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusElasticsearchPlugin\Repository;
14
15
use Doctrine\ORM\EntityRepository;
16
use Sylius\Component\Core\Model\ProductVariantInterface;
17
18
class OrderItemRepository implements OrderItemRepositoryInterface
19
{
20
    /** @var OrderItemRepositoryInterface */
21
    private $baseOrderItemRepository;
22
23
    public function __construct(EntityRepository $baseOrderItemRepository)
24
    {
25
        $this->baseOrderItemRepository = $baseOrderItemRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $baseOrderItemRepository of type Doctrine\ORM\EntityRepository is incompatible with the declared type BitBag\SyliusElasticsear...ItemRepositoryInterface of property $baseOrderItemRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
    }
27
28
    public function countByVariant(ProductVariantInterface $variant): int
29
    {
30
        $qb = $this->baseOrderItemRepository->createQueryBuilder('i');
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on BitBag\SyliusElasticsear...ItemRepositoryInterface. ( Ignorable by Annotation )

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

30
        /** @scrutinizer ignore-call */ 
31
        $qb = $this->baseOrderItemRepository->createQueryBuilder('i');

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...
31
        $qb->select('SUM(i.quantity)')
32
            ->where('i.variant = :variant')
33
            ->setParameter('variant', $variant)
34
            ;
35
36
        return (int) ($qb->getQuery()->getSingleScalarResult());
37
    }
38
}
39