Completed
Pull Request — master (#148)
by Mateusz
09:09
created

OrderItemRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A countByVariant() 0 13 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\OrderInterface;
17
use Sylius\Component\Core\Model\ProductVariantInterface;
18
19
class OrderItemRepository implements OrderItemRepositoryInterface
20
{
21
    /** @var OrderItemRepositoryInterface */
22
    private $baseOrderItemRepository;
23
24
    public function __construct(EntityRepository $baseOrderItemRepository)
25
    {
26
        $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...
27
    }
28
29
    public function countByVariant(ProductVariantInterface $variant): int
30
    {
31
        return (int) ($this->baseOrderItemRepository
32
            ->createQueryBuilder('oi')
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

32
            ->/** @scrutinizer ignore-call */ createQueryBuilder('oi')

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...
33
            ->select('SUM(oi.quantity)')
34
            ->join('oi.order', 'o')
35
            ->select('SUM(oi.quantity)')
36
            ->where('oi.variant = :variant')
37
            ->andWhere('o.state NOT IN (:states)')
38
            ->setParameter('variant', $variant)
39
            ->setParameter('states', [OrderInterface::STATE_CANCELLED, OrderInterface::STATE_CART])
40
            ->getQuery()
41
            ->getSingleScalarResult());
42
    }
43
}
44