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.
Completed
Push — master ( 1537c6...c1251f )
by
unknown
07:51
created

PaymentStateOrdersDataFetcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 14 1
A __construct() 0 3 1
A getType() 0 3 1
A fetch() 0 21 3
1
<?php
2
3
namespace Odiseo\SyliusReportPlugin\DataFetcher;
4
5
use Doctrine\DBAL\Statement;
6
use Doctrine\ORM\EntityManager;
7
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\PaymentStateOrdersType;
8
use Sylius\Component\Order\Model\OrderInterface;
9
10
/**
11
 * @author Diego D'amico <[email protected]>
12
 */
13
class PaymentStateOrdersDataFetcher implements DataFetcherInterface
14
{
15
    /**
16
     * @var EntityManager
17
     */
18
    protected $entityManager;
19
20
    /**
21
     * @param EntityManager $entityManager
22
     */
23
    public function __construct(EntityManager $entityManager)
24
    {
25
        $this->entityManager = $entityManager;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function getData()
32
    {
33
        $queryBuilder = $this->entityManager->getConnection()->createQueryBuilder();
34
35
        $queryBuilder
36
            ->select('o.payment_state as "Payment State"', 'COUNT(o.id) as "Number of orders"')
37
            ->from($this->entityManager->getClassMetadata(OrderInterface::class)->getTableName(), 'o')
38
            ->groupBy('payment_state')
39
        ;
40
41
        /** @var Statement $stmt */
42
        $stmt = $queryBuilder->execute();
43
44
        return $stmt->fetchAll();
45
    }
46
47
    /**
48
     * @param array $configuration
49
     *
50
     * @return Data $data
51
     */
52
    public function fetch(array $configuration)
53
    {
54
        $data = new Data();
55
56
        $rawData = $this->getData();
57
58
        if (empty($rawData)) {
59
            return $data;
60
        }
61
62
        $labels = array_keys($rawData[0]);
63
        $data->setLabels($labels);
64
65
        $fetched = [];
66
        foreach ($rawData as $row) {
67
            $fetched[$row[$labels[0]]] = $row[$labels[1]];
68
        }
69
70
        $data->setData($fetched);
71
72
        return $data;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getType()
79
    {
80
        return PaymentStateOrdersType::class;
81
    }
82
}
83