Completed
Push — wtf-removal ( 4585f3 )
by Kamil
18:08
created

CustomerStatisticsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A renderAction() 0 20 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
namespace Sylius\Bundle\AdminBundle\Controller;
13
14
use Sylius\Component\Core\Customer\Statistics\CustomerStatisticsProviderInterface;
15
use Sylius\Component\Core\Model\ChannelInterface;
16
use Sylius\Component\Core\Model\CustomerInterface;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Exception\HttpException;
22
23
/**
24
 * @author Jan Góralski <[email protected]>
25
 */
26
class CustomerStatisticsController
27
{
28
    /**
29
     * @var CustomerStatisticsProviderInterface
30
     */
31
    private $statisticsProvider;
32
33
    /**
34
     * @var RepositoryInterface
35
     */
36
    private $customerRepository;
37
38
    /**
39
     * @var EngineInterface
40
     */
41
    private $templatingEngine;
42
43
    /**
44
     * @param CustomerStatisticsProviderInterface $statisticsProvider
45
     * @param RepositoryInterface $customerRepository
46
     * @param EngineInterface $templatingEngine
47
     */
48
    public function __construct(
49
        CustomerStatisticsProviderInterface $statisticsProvider,
50
        RepositoryInterface $customerRepository,
51
        EngineInterface $templatingEngine
52
    ) {
53
        $this->statisticsProvider = $statisticsProvider;
54
        $this->customerRepository = $customerRepository;
55
        $this->templatingEngine = $templatingEngine;
56
    }
57
58
    /**
59
     * @param Request $request
60
     *
61
     * @return Response
62
     *
63
     * @throws HttpException
64
     */
65
    public function renderAction(Request $request)
66
    {
67
        $customerId = $request->query->get('customerId');
68
69
        /** @var CustomerInterface $customer */
70
        $customer = $this->customerRepository->find($customerId);
71
        if (null === $customer) {
72
            throw new HttpException(
73
                Response::HTTP_BAD_REQUEST,
74
                sprintf('Customer with id %s doesn\'t exist.', $customerId)
75
            );
76
        }
77
78
        $customerStatistics = $this->statisticsProvider->getCustomerStatistics($customer);
79
80
        return $this->templatingEngine->renderResponse(
81
            '@SyliusAdmin/Customer/Show/Statistics/statistics.html.twig',
82
            ['statistics' => $customerStatistics]
83
        );
84
    }
85
}
86