Completed
Pull Request — experimental/sf (#3393)
by chihiro
41:59
created

EccubeDataCollector::getPlugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 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\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
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$pluginRepository" missing
Loading history...
42
     * @param ContainerInterface $container
43
     */
44 428
    public function __construct(ContainerInterface $container, PluginRepository $pluginRepository)
45
    {
46 428
        $this->data = [
47 428
            '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 428
        $this->container = $container;
55 428
        $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 43
    public function collect(Request $request, Response $response, \Exception $exception = null)
110
    {
111 43
        $this->data['base_currency_code'] = $this->container->getParameter('currency');
112 43
        $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
        }
118
119
        try {
120 43
            $enabled = $this->container->getParameter('eccube.plugins.enabled');
121 43
            $disabled = $this->container->getParameter('eccube.plugins.disabled');
122
123 43
            foreach (array_merge($enabled, $disabled) as $code) {
124 43
                $Plugin = $this->pluginRepository->findBy(['code' => $code]);
125 43
                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 43
                    $Plugin = new Plugin();
127 43
                    $Plugin->setCode($code);
128 43
                    $Plugin->setName($code);
129 43
                    $Plugin->setEnabled(false);
130
                }
131 43
                $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 428
    public function getName()
146
    {
147 428
        return 'eccube_core';
148
    }
149
}
150