Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
51:40 queued 07:20
created

EccubeDataCollector::collect()   A

Complexity

Conditions 5
Paths 34

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0488

Importance

Changes 0
Metric Value
cc 5
nc 34
nop 3
dl 0
loc 27
ccs 14
cts 16
cp 0.875
crap 5.0488
rs 9.1768
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 430
    public function __construct(ContainerInterface $container, PluginRepository $pluginRepository)
45
    {
46 430
        $this->data = [
47 430
            '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 430
        $this->container = $container;
55 430
        $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 39
    public function collect(Request $request, Response $response, \Exception $exception = null)
110
    {
111 39
        $this->data['base_currency_code'] = $this->container->getParameter('currency');
112 39
        $this->data['currency_code'] = $this->container->getParameter('currency');
113
114
        try {
115 39
            $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 39
            $enabled = $this->container->getParameter('eccube.plugins.enabled');
121 39
            $disabled = $this->container->getParameter('eccube.plugins.disabled');
122
123 39
            foreach (array_merge($enabled, $disabled) as $code) {
124 39
                $Plugin = $this->pluginRepository->findBy(['code' => $code]);
125 39
                if (!$Plugin) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $Plugin of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
126 39
                    $Plugin = new Plugin();
127 39
                    $Plugin->setCode($code);
128 39
                    $Plugin->setName($code);
129 39
                    $Plugin->setEnabled(false);
130
                }
131 39
                $this->data['plugins'][$code] = $Plugin;
132
            }
133
        } 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
137 1
    public function reset()
138
    {
139 1
        $this->data = [];
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145 430
    public function getName()
146
    {
147 430
        return 'eccube_core';
148
    }
149
}
150