Completed
Push — sf/composer-install-update ( a1e834 )
by Kiyotaka
10:44
created

EccubeDataCollector::collect()   B

Complexity

Conditions 7
Paths 112

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 112
nop 3
dl 0
loc 37
rs 8.3146
c 0
b 0
f 0
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
            'currency_code' => null,
50
            'default_locale_code' => null,
51
            'locale_code' => null,
52
            'plugins' => [],
53
        ];
54
        $this->container = $container;
55
        $this->pluginRepository = $pluginRepository;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    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
            $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
        }
118
119
        try {
120
            $enabled = $this->container->getParameter('eccube.plugins.enabled');
121
            $disabled = $this->container->getParameter('eccube.plugins.disabled');
122
123
            $Plugins = $this->pluginRepository->findAll();
124
            foreach (array_merge($enabled, $disabled) as $code) {
125
                $Plugin = null;
126
127
                /** @var Plugin $Plugin */
128
                foreach ($Plugins as $p) {
129
                    if ($code == $p->getCode()) {
130
                        $Plugin = $p;
131
                        break;
132
                    }
133
                }
134
135
                if (!$Plugin) {
136
                    $Plugin = new Plugin();
137
                    $Plugin->setCode($code);
138
                    $Plugin->setName($code);
139
                    $Plugin->setEnabled(false);
140
                }
141
                $this->data['plugins'][$code] = $Plugin;
142
            }
143
        } catch (\Exception $exception) {
144
        }
145
    }
146
147
    public function reset()
148
    {
149
        $this->data = [];
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function getName()
156
    {
157
        return 'eccube_core';
158
    }
159
}
160