Failed Conditions
Pull Request — experimental/sf (#31)
by Kentaro
06:59
created

EccubeDataCollector::collect()   A

Complexity

Conditions 5
Paths 34

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.583

Importance

Changes 0
Metric Value
cc 5
nc 34
nop 3
dl 0
loc 27
rs 9.1768
c 0
b 0
f 0
ccs 10
cts 14
cp 0.7143
crap 5.583
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\DataCollector;
15
16
use Eccube\Common\Constant;
17
use Eccube\Entity\Plugin;
18
use Eccube\Repository\PluginRepository;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
23
24
/**
25
 * EccubeDataCollector.
26
 *
27
 * @see https://github.com/Sylius/SyliusCoreBundle/blob/master/Collector/SyliusCollector.php
28
 */
29
class EccubeDataCollector extends DataCollector
30
{
31
    /**
32
     * @var ContainerInterface
33
     */
34
    protected $container;
35
36
    /**
37
     * @var PluginRepository
38
     */
39
    protected $pluginRepository;
40
41
    /**
42
     * @param ContainerInterface $container
43
     */
44
    public function __construct(ContainerInterface $container, PluginRepository $pluginRepository)
45
    {
46
        $this->data = [
47
            'version' => Constant::VERSION,
48
            'base_currency_code' => null,
49 431
            'currency_code' => null,
50
            'default_locale_code' => null,
51 431
            'locale_code' => null,
52 431
            'plugins' => [],
53
        ];
54
        $this->container = $container;
55
        $this->pluginRepository = $pluginRepository;
56
    }
57
58
    /**
59 431
     * @return string
60 431
     */
61 431
    public function getVersion()
62
    {
63
        return $this->data['version'];
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getPlugins()
70
    {
71
        return $this->data['plugins'];
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getCurrencyCode()
78
    {
79
        return $this->data['currency_code'];
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getLocaleCode()
86
    {
87
        return $this->data['locale_code'];
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getDefaultCurrencyCode()
94
    {
95
        return $this->data['base_currency_code'];
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getDefaultLocaleCode()
102
    {
103
        return $this->data['default_locale_code'];
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function collect(Request $request, Response $response, \Exception $exception = null)
110
    {
111
        $this->data['base_currency_code'] = $this->container->getParameter('currency');
112
        $this->data['currency_code'] = $this->container->getParameter('currency');
113
114
        try {
115 43
            $this->data['locale_code'] = $this->container->getParameter('locale');
116
        } catch (LocaleNotFoundException $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class Eccube\DataCollector\LocaleNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
117 43
        }
118 43
119
        try {
120
            $enabled = $this->container->getParameter('eccube.plugins.enabled');
121 43
            $disabled = $this->container->getParameter('eccube.plugins.disabled');
122
123
            foreach (array_merge($enabled, $disabled) as $code) {
124
                $Plugin = $this->pluginRepository->findOneBy(['code' => $code]);
125
                if (!$Plugin) {
126 43
                    $Plugin = new Plugin();
127 43
                    $Plugin->setCode($code);
128
                    $Plugin->setName($code);
129 43
                    $Plugin->setEnabled(false);
130 43
                }
131
                $this->data['plugins'][$code] = $Plugin;
132 43
            }
133 43
        } catch (\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
134
        }
135
    }
136 43
137
    public function reset()
138
    {
139
        $this->data = [];
140
    }
141
142
    /**
143 1
     * {@inheritdoc}
144
     */
145 1
    public function getName()
146
    {
147
        return 'eccube_core';
148
    }
149
}
150