Completed
Push — AdamKasp--refactor-and-upgrade... ( dfa618...fc27b6 )
by Kamil
05:14
created

DashboardStatisticsProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Core\Dashboard;
15
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
18
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
19
20
class DashboardStatisticsProvider implements DashboardStatisticsProviderInterface
21
{
22
    /** @var OrderRepositoryInterface */
23
    private $orderRepository;
24
25
    /** @var CustomerRepositoryInterface */
26
    private $customerRepository;
27
28
    public function __construct(
29
        OrderRepositoryInterface $orderRepository,
30
        CustomerRepositoryInterface $customerRepository
31
    ) {
32
        $this->orderRepository = $orderRepository;
33
        $this->customerRepository = $customerRepository;
34
    }
35
36
    public function getStatisticsForChannel(ChannelInterface $channel): DashboardStatistics
37
    {
38
        return new DashboardStatistics(
39
            $this->orderRepository->getTotalPaidSalesForChannel($channel),
40
            $this->orderRepository->countPaidByChannel($channel),
41
            $this->customerRepository->countCustomers()
42
        );
43
    }
44
45
    public function getStatisticsForChannelInPeriod(
46
        ChannelInterface $channel,
47
        \DateTimeInterface $startDate,
48
        \DateTimeInterface $endDate
49
    ): DashboardStatistics {
50
        return new DashboardStatistics(
51
            $this->orderRepository->getTotalPaidSalesForChannelInPeriod($channel, $startDate, $endDate),
52
            $this->orderRepository->countPaidForChannelInPeriod($channel, $startDate, $endDate),
53
            $this->customerRepository->countCustomersInPeriod($startDate, $endDate)
54
        );
55
    }
56
}
57