GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SalesTotalDataFetcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 53
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupQueryFilter() 0 32 1
A __construct() 0 7 1
A getType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusReportPlugin\DataFetcher;
6
7
use Exception;
8
use Odiseo\SyliusReportPlugin\Filter\QueryFilterInterface;
9
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\SalesTotalType;
10
use Sylius\Component\Core\Model\PaymentInterface;
11
use Sylius\Component\Core\OrderPaymentStates;
12
13
/**
14
 * @author Łukasz Chruściel <[email protected]>
15
 * @author Diego D'amico <[email protected]>
16
 */
17
class SalesTotalDataFetcher extends TimePeriodDataFetcher
18
{
19
    private string $orderClass;
20
21
    public function __construct(
22
        QueryFilterInterface $queryFilter,
23
        string $orderClass
24
    ) {
25
        parent::__construct($queryFilter);
26
27
        $this->orderClass = $orderClass;
28
    }
29
30
    /**
31
     * @throws Exception
32
     */
33
    protected function setupQueryFilter(array $configuration = []): void
34
    {
35
        $qb = $this->queryFilter->getQueryBuilder();
36
37
        $from = $this->orderClass;
38
        $qb
39
            ->select('DATE(payment.updatedAt) as date', 'COUNT(DATE(payment.updatedAt)) as orders_quantity', 'ROUND(SUM(o.total/100), 2) as gross_total_money')
40
            ->from($from, 'o')
41
        ;
42
43
        $this->queryFilter->addLeftJoin('o.customer', 'c');
44
        $this->queryFilter->addLeftJoin('c.user', 'user');
45
        $this->queryFilter->addLeftJoin('o.payments', 'payment');
46
47
        $qb
48
            ->andWhere('o.paymentState = :paymentState')
49
            ->andWhere('payment.state = :state')
50
            ->setParameter('paymentState', OrderPaymentStates::STATE_PAID)
51
            ->setParameter('state', PaymentInterface::STATE_COMPLETED)
52
        ;
53
54
        $this->queryFilter->addTimePeriod($configuration, 'payment.updatedAt');
55
        $this->queryFilter->addChannel($configuration, 'o.channel');
56
        $this->queryFilter->addUserGender($configuration);
57
        $this->queryFilter->addUserCountry($configuration, 'shipping');
58
        $this->queryFilter->addUserCity($configuration, 'shipping');
59
        $this->queryFilter->addUserProvince($configuration, 'shipping');
60
        $this->queryFilter->addUserPostcode($configuration, 'shipping');
61
        $this->queryFilter->addUserCountry($configuration, 'billing');
62
        $this->queryFilter->addUserCity($configuration, 'billing');
63
        $this->queryFilter->addUserProvince($configuration, 'billing');
64
        $this->queryFilter->addUserPostcode($configuration, 'billing');
65
    }
66
67
    public function getType(): string
68
    {
69
        return SalesTotalType::class;
70
    }
71
}
72