Completed
Push — sf/improvement-coverage ( b3937e...01a837 )
by Kiyotaka
51:20 queued 45:08
created

UserDataController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
ccs 20
cts 20
cp 1
wmc 3
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 31 2
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Controller;
15
16
use Eccube\Entity\Master\DeviceType;
17
use Eccube\Entity\Page;
18
use Eccube\Event\EccubeEvents;
19
use Eccube\Event\EventArgs;
20
use Eccube\Repository\Master\DeviceTypeRepository;
21
use Eccube\Repository\PageRepository;
22
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
25
26
class UserDataController extends AbstractController
27
{
28
    /**
29
     * @var PageRepository
30
     */
31
    protected $pageRepository;
32
33
    /**
34
     * @var DeviceTypeRepository
35
     */
36
    protected $deviceTypeRepository;
37
38
    /**
39
     * UserDataController constructor.
40
     *
41
     * @param PageRepository $pageRepository
42
     * @param DeviceTypeRepository $deviceTypeRepository
43
     */
44 2
    public function __construct(
45
        PageRepository $pageRepository,
46
        DeviceTypeRepository $deviceTypeRepository
47
    ) {
48 2
        $this->pageRepository = $pageRepository;
49 2
        $this->deviceTypeRepository = $deviceTypeRepository;
50
    }
51
52
    /**
53
     * @Route("/%eccube_user_data_route%/{route}", name="user_data", requirements={"route": "([0-9a-zA-Z_\-]+\/?)+(?<!\/)"})
54
     */
55 2
    public function index(Request $request, $route)
56
    {
57 2
        $DeviceType = $this->deviceTypeRepository
58 2
            ->find(DeviceType::DEVICE_TYPE_PC);
59
60 2
        $Page = $this->pageRepository->findOneBy(
61
            [
62 2
                'url' => $route,
63 2
                'DeviceType' => $DeviceType,
64 2
                'edit_type' => Page::EDIT_TYPE_USER,
65
            ]
66
        );
67
68 2
        if (null === $Page) {
69 1
            throw new NotFoundHttpException();
70
        }
71
72 1
        $file = sprintf('@user_data/%s.twig', $Page->getFileName());
73
74 1
        $event = new EventArgs(
75
            [
76 1
                'DeviceType' => $DeviceType,
77 1
                'Page' => $Page,
78 1
                'file' => $file,
79
            ],
80 1
            $request
81
        );
82 1
        $this->eventDispatcher->dispatch(EccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE, $event);
83
84 1
        return $this->render($file);
85
    }
86
}
87