Failed Conditions
Pull Request — master (#1695)
by Kentaro
206:13 queued 198:54
created

Application::initDoctrine()   D

Complexity

Conditions 12
Paths 165

Size

Total Lines 80
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 17.3317

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 80
ccs 28
cts 42
cp 0.6667
rs 4.7227
cc 12
eloc 50
nc 165
nop 0
crap 17.3317

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube;
25
26
use Eccube\Application\ApplicationTrait;
27
use Eccube\Common\Constant;
28
use Eccube\EventListener\TransactionListener;
29
use Monolog\Logger;
30
use Symfony\Component\EventDispatcher\EventDispatcher;
31
use Symfony\Component\Finder\Finder;
32
use Symfony\Component\HttpFoundation\Request;
33
use Symfony\Component\HttpFoundation\Response;
34
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
35
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
36
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
37
use Symfony\Component\HttpKernel\KernelEvents;
38
use Symfony\Component\Yaml\Yaml;
39
40
class Application extends ApplicationTrait
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
41
{
42
    protected static $instance;
43
44
    protected $initialized = false;
45
    protected $initializedPlugin = false;
46
    protected $testMode = false;
47
48 998
    public static function getInstance(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
49
    {
50 998
        if (!is_object(self::$instance)) {
51 932
            self::$instance = new Application($values);
52
        }
53
54 998
        return self::$instance;
55
    }
56
57 933
    public static function clearInstance()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
58
    {
59 933
        self::$instance = null;
60
    }
61
62
    final public function __clone()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
63
    {
64
        throw new \Exception('Clone is not allowed against '.get_class($this));
65
    }
66
67 946
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
68
    {
69 946
        parent::__construct($values);
70
71 946
        if (is_null(self::$instance)) {
72 933
            self::$instance = $this;
73
        }
74
75
        // load config
76 946
        $this->initConfig();
77
78
        // init monolog
79 946
        $this->initLogger();
80
    }
81
82 946
    public function initConfig()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
83
    {
84
        // load config
85 946
        $app = $this;
86
        $this['config'] = $this->share(function() use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
87 939
            $configAll = array();
88 939
            $app->parseConfig('constant', $configAll)
89 939
                ->parseConfig('path', $configAll)
90 939
                ->parseConfig('config', $configAll)
91 939
                ->parseConfig('database', $configAll)
92 939
                ->parseConfig('mail', $configAll)
93 939
                ->parseConfig('log', $configAll)
94 939
                ->parseConfig('nav', $configAll, true)
95 939
                ->parseConfig('doctrine_cache', $configAll);
96 939
            return $configAll;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
97 946
        });
98
    }
99
100 946
    public function initLogger()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
101
    {
102 946
        $app = $this;
103 946
        $this->register(new ServiceProvider\EccubeMonologServiceProvider($app));
0 ignored issues
show
Unused Code introduced by
The call to EccubeMonologServiceProvider::__construct() has too many arguments starting with $app.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
104 946
        $this['monolog.logfile'] = __DIR__.'/../../app/log/site.log';
105 946
        $this['monolog.name'] = 'eccube';
106
    }
107
108 936
    public function initialize()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
109
    {
110 936
        if ($this->initialized) {
111
            return;
112
        }
113
114
        // init locale
115 936
        $this->initLocale();
116
117
        // init session
118 936
        $this->initSession();
119
120
        // init twig
121 936
        $this->initRendering();
122
123
        // init provider
124 936
        $this->register(new \Silex\Provider\HttpFragmentServiceProvider());
125 936
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
126 936
        $this->register(new \Silex\Provider\FormServiceProvider());
127 936
        $this->register(new \Silex\Provider\SerializerServiceProvider());
128 936
        $this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
129
130 936
        $app = $this;
131
        $this->error(function(\Exception $e, $code) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
132 10
            if ($app['debug']) {
133 10
                return;
134
            }
135
136
            switch ($code) {
137
                case 403:
138
                    $title = 'アクセスできません。';
139
                    $message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。';
140
                    break;
141
                case 404:
142
                    $title = 'ページがみつかりません。';
143
                    $message = 'URLに間違いがないかご確認ください。';
144
                    break;
145
                default:
146
                    $title = 'システムエラーが発生しました。';
147
                    $message = '大変お手数ですが、サイト管理者までご連絡ください。';
148
                    break;
149
            }
150
151
            return $app->render('error.twig', array(
152
                'error_title' => $title,
153
                'error_message' => $message,
154
            ));
155 936
        });
156
157
        // init mailer
158 936
        $this->initMailer();
159
160
        // init doctrine orm
161 936
        $this->initDoctrine();
162
163
        // Set up the DBAL connection now to check for a proper connection to the database.
164 936
        $this->checkDatabaseConnection();
165
166
        // init security
167 936
        $this->initSecurity();
168
169
        // init ec-cube service provider
170 936
        $this->register(new ServiceProvider\EccubeServiceProvider());
171
172
        // mount controllers
173 936
        $this->register(new \Silex\Provider\ServiceControllerServiceProvider());
174 936
        $this->mount('', new ControllerProvider\FrontControllerProvider());
175 936
        $this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider());
176 936
        Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする
177
178
        // add transaction listener
179 936
        $this['dispatcher']->addSubscriber(new TransactionListener($this));
180
181 936
        $this->initialized = true;
182
    }
183
184 936
    public function initLocale()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
185
    {
186
187
        // timezone
188 936
        if (!empty($this['config']['timezone'])) {
189 936
            date_default_timezone_set($this['config']['timezone']);
190
        }
191
192 936
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
193 936
            'locale' => $this['config']['locale'],
194
        ));
195
        $this['translator'] = $this->share($this->extend('translator', function($translator, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
196 605
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
197
198 605
            $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
199 605
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
200 605
            if (file_exists($file)) {
201 605
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
202
            }
203
204 605
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
205 605
            if (file_exists($file)) {
206 605
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
207
            }
208
209 605
            $file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml';
210 605
            if (file_exists($file)) {
211 605
                $translator->addResource('yaml', $file, $app['locale']);
212
            }
213
214 605
            return $translator;
215 936
        }));
216
    }
217
218 936
    public function initSession()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
219
    {
220 936
        $this->register(new \Silex\Provider\SessionServiceProvider(), array(
221 936
            'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session',
222
            'session.storage.options' => array(
223 936
                'name' => 'eccube',
224 936
                'cookie_path' => $this['config']['root_urlpath'] ?: '/',
225 936
                'cookie_secure' => $this['config']['force_ssl'],
226 936
                'cookie_lifetime' => $this['config']['cookie_lifetime'],
227
                'cookie_httponly' => true,
228
                // cookie_domainは指定しない
229
                // http://blog.tokumaru.org/2011/10/cookiedomain.html
230
            ),
231
        ));
232
    }
233
234 936
    public function initRendering()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
235
    {
236 936
        $this->register(new \Silex\Provider\TwigServiceProvider(), array(
237 936
            'twig.form.templates' => array('Form/form_layout.twig'),
238
        ));
239
        $this['twig'] = $this->share($this->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
240 364
            $twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app));
241 364
            $twig->addExtension(new \Twig_Extension_StringLoader());
242
243 364
            return $twig;
244 936
        }));
245
246
        $this->before(function(Request $request, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
247
            // フロント or 管理画面ごとにtwigの探索パスを切り替える.
248
            $app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
249 351
                $paths = array();
250
251
                // 互換性がないのでprofiler とproduction 時のcacheを分離する
252
253 351
                $app['admin'] = false;
254 351
                $app['front'] = false;
255
256 351
                if (isset($app['profiler'])) {
257
                    $cacheBaseDir = __DIR__.'/../../app/cache/twig/profiler/';
258
                } else {
259 351
                    $cacheBaseDir = __DIR__.'/../../app/cache/twig/production/';
260
                }
261 351
                $pathinfo = rawurldecode($app['request']->getPathInfo());
262 351
                if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
263 187
                    if (file_exists(__DIR__.'/../../app/template/admin')) {
264 187
                        $paths[] = __DIR__.'/../../app/template/admin';
265
                    }
266 187
                    $paths[] = $app['config']['template_admin_realdir'];
267 187
                    $paths[] = __DIR__.'/../../app/Plugin';
268 187
                    $cache = $cacheBaseDir.'admin';
269 187
                    $app['admin'] = true;
270
                } else {
271 165
                    if (file_exists($app['config']['template_realdir'])) {
272 165
                        $paths[] = $app['config']['template_realdir'];
273
                    }
274 165
                    $paths[] = $app['config']['template_default_realdir'];
275 165
                    $paths[] = __DIR__.'/../../app/Plugin';
276 165
                    $cache = $cacheBaseDir.$app['config']['template_code'];
277 165
                    $app['front'] = true;
278
                }
279 351
                $twig->setCache($cache);
280 351
                $app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths));
281
282 351
                return $twig;
283 353
            }));
284
285
            // 管理画面のIP制限チェック.
286 353
            $pathinfo = rawurldecode($app['request']->getPathInfo());
287 353
            if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
288
                // IP制限チェック
289 187
                $allowHost = $app['config']['admin_allow_host'];
290 187
                if (count($allowHost) > 0) {
291
                    if (array_search($app['request']->getClientIp(), $allowHost) === false) {
292
                        throw new \Exception();
293
                    }
294
                }
295
            }
296 936
        }, self::EARLY_EVENT);
297
298
        // twigのグローバル変数を定義.
299 936
        $app = $this;
300
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
301
            // ショップ基本情報
302 351
            $BaseInfo = $app['eccube.repository.base_info']->get();
303 351
            $app['twig']->addGlobal('BaseInfo', $BaseInfo);
304
305 351
            $pathinfo = rawurldecode($app['request']->getPathInfo());
306 351
            if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
307
                // 管理画面
308
                // 管理画面メニュー
309 187
                $menus = array('', '', '');
310 187
                $app['twig']->addGlobal('menus', $menus);
311
312 187
                $Member = $app->user();
313 187
                if (is_object($Member)) {
314
                    // ログインしていれば管理者のロールを取得
315 181
                    $AuthorityRoles = $app['eccube.repository.authority_role']->findBy(array('Authority' => $Member->getAuthority()));
316
317 181
                    $roles = array();
318 181
                    foreach ($AuthorityRoles as $AuthorityRole) {
319
                        // 管理画面でメニュー制御するため相対パス全てをセット
320 181
                        $roles[] = $app['request']->getBaseUrl().'/'.$app['config']['admin_route'].$AuthorityRole->getDenyUrl();
321
                    }
322
323 187
                    $app['twig']->addGlobal('AuthorityRoles', $roles);
324
                }
325
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
326
            } else {
327
                // フロント画面
328 165
                $request = $event->getRequest();
329 165
                $route = $request->attributes->get('_route');
330
331
                // ユーザ作成画面
332 165
                if ($route === trim($app['config']['user_data_route'])) {
333 2
                    $params = $request->attributes->get('_route_params');
334 2
                    $route = $params['route'];
335
                    // プレビュー画面
336 163
                } elseif ($request->get('preview')) {
337
                    $route = 'preview';
338
                }
339
340
                try {
341 165
                    $DeviceType = $app['eccube.repository.master.device_type']
342 165
                        ->find(\Eccube\Entity\Master\DeviceType::DEVICE_TYPE_PC);
343 165
                    $PageLayout = $app['eccube.repository.page_layout']->getByUrl($DeviceType, $route);
344 135
                } catch (\Doctrine\ORM\NoResultException $e) {
345 135
                    $PageLayout = $app['eccube.repository.page_layout']->newPageLayout($DeviceType);
346
                }
347
348 165
                $app['twig']->addGlobal('PageLayout', $PageLayout);
349 165
                $app['twig']->addGlobal('title', $PageLayout->getName());
350
            }
351 936
        });
352
    }
353
354 936
    public function initMailer()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
355
    {
356
357
        // メール送信時の文字エンコード指定(デフォルトはUTF-8)
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
358 936
        if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) {
359 936
            if ($this['config']['mail']['charset_iso_2022_jp'] === true) {
360
                \Swift::init(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
361
                    \Swift_DependencyContainer::getInstance()
362
                        ->register('mime.qpheaderencoder')
363
                        ->asAliasOf('mime.base64headerencoder');
364
                    \Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
365
                });
366
            }
367
        }
368
369 936
        $this->register(new \Silex\Provider\SwiftmailerServiceProvider());
370 936
        $this['swiftmailer.options'] = $this['config']['mail'];
371
372 936
        if (isset($this['config']['mail']['spool']) && is_bool($this['config']['mail']['spool'])) {
373
            $this['swiftmailer.use_spool'] = $this['config']['mail']['spool'];
374
        }
375
        // デフォルトはsmtpを使用
376 936
        $transport = $this['config']['mail']['transport'];
377 936
        if ($transport == 'sendmail') {
378
            $this['swiftmailer.transport'] = \Swift_SendmailTransport::newInstance();
379 936
        } elseif ($transport == 'mail') {
380
            $this['swiftmailer.transport'] = \Swift_MailTransport::newInstance();
381
        }
382
    }
383
384 936
    public function initDoctrine()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
385
    {
386 936
        $this->register(new \Silex\Provider\DoctrineServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
387
            'dbs.options' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
388 936
                'default' => $this['config']['database']
389
        )));
390 936
        $this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider());
391
392
        // プラグインのmetadata定義を合わせて行う.
393 936
        $pluginBasePath = __DIR__.'/../../app/Plugin';
394 936
        $finder = Finder::create()
395 936
            ->in($pluginBasePath)
396 936
            ->directories()
397 936
            ->depth(0);
398
399 936
        $ormMappings = array();
400 936
        $ormMappings[] = array(
401
            'type' => 'yml',
402
            'namespace' => 'Eccube\Entity',
403
            'path' => array(
404
                __DIR__.'/Resource/doctrine',
405
                __DIR__.'/Resource/doctrine/master',
406
            ),
407
        );
408
409 936
        foreach ($finder as $dir) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
410
411 139
            $file = $dir->getRealPath().'/config.yml';
412
413 139
            if (file_exists($file)) {
414 139
                $config = Yaml::parse(file_get_contents($file));
415
            } else {
416
                $code = $dir->getBaseName();
417
                $this['monolog']->warning("skip {$code} orm.path loading. config.yml not found.", array('path' => $file));
418
                continue;
419
            }
420
421
            // Doctrine Extend
422 139
            if (isset($config['orm.path']) && is_array($config['orm.path'])) {
423
                $paths = array();
424
                foreach ($config['orm.path'] as $path) {
425
                    $paths[] = $pluginBasePath.'/'.$config['code'].$path;
426
                }
427
                $ormMappings[] = array(
428
                    'type' => 'yml',
429
                    'namespace' => 'Plugin\\'.$config['code'].'\\Entity',
430 936
                    'path' => $paths,
431
                );
432
            }
433
        }
434
435
        $options = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
436 936
            'mappings' => $ormMappings
437
        );
438
439 936
        if (!$this['debug']) {
440 3
            $cacheDrivers = array();
441 3
            if (array_key_exists('doctrine_cache', $this['config'])) {
442
                $cacheDrivers = $this['config']['doctrine_cache'];
443
            }
444
445 3
            if (array_key_exists('metadata_cache', $cacheDrivers)) {
446
                $options['metadata_cache'] = $cacheDrivers['metadata_cache'];
447
            }
448 3
            if (array_key_exists('query_cache', $cacheDrivers)) {
449
                $options['query_cache'] = $cacheDrivers['query_cache'];
450
            }
451 3
            if (array_key_exists('result_cache', $cacheDrivers)) {
452
                $options['result_cache'] = $cacheDrivers['result_cache'];
453
            }
454 3
            if (array_key_exists('hydration_cache', $cacheDrivers)) {
455
                $options['hydration_cache'] = $cacheDrivers['hydration_cache'];
456
            }
457
        }
458
459 936
        $this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
460 936
            'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine/proxies',
461 936
            'orm.em.options' => $options
462
        ));
463
    }
464
465 936
    public function initSecurity()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
466
    {
467 936
        $this->register(new \Silex\Provider\SecurityServiceProvider());
468 936
        $this->register(new \Silex\Provider\RememberMeServiceProvider());
469
470 936
        $this['security.firewalls'] = array(
471
            'admin' => array(
472 936
                'pattern' => "^/{$this['config']['admin_route']}/",
473
                'form' => array(
474 936
                    'login_path' => "/{$this['config']['admin_route']}/login",
475 936
                    'check_path' => "/{$this['config']['admin_route']}/login_check",
476 936
                    'username_parameter' => 'login_id',
477 936
                    'password_parameter' => 'password',
478
                    'with_csrf' => true,
479
                    'use_forward' => true,
480
                ),
481
                'logout' => array(
482 936
                    'logout_path' => "/{$this['config']['admin_route']}/logout",
483 936
                    'target_url' => "/{$this['config']['admin_route']}/",
484
                ),
485 936
                'users' => $this['orm.em']->getRepository('Eccube\Entity\Member'),
486
                'anonymous' => true,
487 936
            ),
488
            'customer' => array(
489 936
                'pattern' => '^/',
490
                'form' => array(
491
                    'login_path' => '/mypage/login',
492
                    'check_path' => '/login_check',
493
                    'username_parameter' => 'login_email',
494
                    'password_parameter' => 'login_pass',
495
                    'with_csrf' => true,
496
                    'use_forward' => true,
497
                ),
498
                'logout' => array(
499
                    'logout_path' => '/logout',
500
                    'target_url' => '/',
501
                ),
502
                'remember_me' => array(
503 936
                    'key' => sha1($this['config']['auth_magic']),
504 936
                    'name' => 'eccube_rememberme',
505
                    // lifetimeはデフォルトの1年間にする
506
                    // 'lifetime' => $this['config']['cookie_lifetime'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
507 936
                    'path' => $this['config']['root_urlpath'] ?: '/',
508 936
                    'secure' => $this['config']['force_ssl'],
509
                    'httponly' => true,
510
                    'always_remember_me' => false,
511 936
                    'remember_me_parameter' => 'login_memory',
512
                ),
513 936
                'users' => $this['orm.em']->getRepository('Eccube\Entity\Customer'),
514
                'anonymous' => true,
515
            ),
516
        );
517
518 936
        $this['security.access_rules'] = array(
519 936
            array("^/{$this['config']['admin_route']}/login", 'IS_AUTHENTICATED_ANONYMOUSLY'),
520 936
            array("^/{$this['config']['admin_route']}/", 'ROLE_ADMIN'),
521
            array('^/mypage/login', 'IS_AUTHENTICATED_ANONYMOUSLY'),
522
            array('^/mypage/withdraw_complete', 'IS_AUTHENTICATED_ANONYMOUSLY'),
523
            array('^/mypage/change', 'IS_AUTHENTICATED_FULLY'),
524
            array('^/mypage', 'ROLE_USER'),
525
        );
526
527
        $this['eccube.password_encoder'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
528 936
            return new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']);
529 936
        });
530
        $this['security.encoder_factory'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
531 936
            return new \Symfony\Component\Security\Core\Encoder\EncoderFactory(array(
532 936
                'Eccube\Entity\Customer' => $app['eccube.password_encoder'],
533 936
                'Eccube\Entity\Member' => $app['eccube.password_encoder'],
534
            ));
535 936
        });
536
        $this['eccube.event_listner.security'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
537 936
            return new \Eccube\EventListener\SecurityEventListener($app['orm.em']);
538 936
        });
539
        $this['user'] = function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
540 256
            $token = $app['security']->getToken();
541
542 256
            return ($token !== null) ? $token->getUser() : null;
543
        };
544
545
        // ログイン時のイベントを設定.
546 936
        $this['dispatcher']->addListener(\Symfony\Component\Security\Http\SecurityEvents::INTERACTIVE_LOGIN, array($this['eccube.event_listner.security'], 'onInteractiveLogin'));
547
548
        // Voterの設定
549 936
        $app = $this;
550
        $this['authority_voter'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
551 936
            return new \Eccube\Security\Voter\AuthorityVoter($app);
552 936
        });
553
554
        $app['security.voters'] = $app->extend('security.voters', function($voters) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
555 936
            $voters[] = $app['authority_voter'];
556
557 936
            return $voters;
558 936
        });
559
560
        $this['security.access_manager'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
561 936
            return new \Symfony\Component\Security\Core\Authorization\AccessDecisionManager($app['security.voters'], 'unanimous');
562 936
        });
563
564
    }
565
566 936
    public function initializePlugin()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
567
    {
568 936
        if ($this->initializedPlugin) {
569
            return;
570
        }
571
572
        // setup event dispatcher
573 936
        $this->initPluginEventDispatcher();
574
575
        // load plugin
576 936
        $this->loadPlugin();
577
578 936
        $this->initializedPlugin = true;
579
    }
580
581 936
    public function initPluginEventDispatcher()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
582
    {
583
        // EventDispatcher
584
        $this['eccube.event.dispatcher'] = $this->share(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
585 366
            return new EventDispatcher();
586 936
        });
587
588 936
        $app = $this;
589
590
        // hook point
591
        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($app) {
592 353
            if (!$event->isMasterRequest()) {
593 98
                return;
594
            }
595 353
            $hookpoint = 'eccube.event.app.before';
596 353
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
597 936
        }, self::EARLY_EVENT);
598
599 View Code Duplication
        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
600 352
            if (!$event->isMasterRequest()) {
601 98
                return;
602
            }
603 350
            $route = $event->getRequest()->attributes->get('_route');
604 350
            $hookpoint = "eccube.event.controller.$route.before";
605 350
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
606 936
        });
607
608 View Code Duplication
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
609 347
            if (!$event->isMasterRequest()) {
610 98
                return;
611
            }
612 347
            $route = $event->getRequest()->attributes->get('_route');
613 347
            $hookpoint = "eccube.event.controller.$route.after";
614 347
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
615 936
        });
616
617
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) {
618 347
            if (!$event->isMasterRequest()) {
619 98
                return;
620
            }
621 347
            $hookpoint = 'eccube.event.app.after';
622 347
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
623 936
        }, self::LATE_EVENT);
624
625
        $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($app) {
626 347
            $route = $event->getRequest()->attributes->get('_route');
627 347
            $hookpoint = "eccube.event.controller.$route.finish";
628 347
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
629 936
        });
630
631
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
632 347
            $route = $event->getRequest()->attributes->get('_route');
633 347
            $app['eccube.event.dispatcher']->dispatch('eccube.event.render.'.$route.'.before', $event);
634 936
        });
635
636
        // Request Event
637 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function(\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
638
639 352
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
640 98
                return;
641
            }
642
643 352
            $route = $event->getRequest()->attributes->get('_route');
644
645 352
            if (is_null($route)) {
646
                return;
647
            }
648
649 352
            $app['monolog']->debug('KernelEvents::REQUEST '.$route);
650
651
            // 全体
652 352
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.request', $event);
653
654 352
            if (strpos($route, 'admin') === 0) {
655
                // 管理画面
656 187
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.request', $event);
657
            } else {
658
                // フロント画面
659 166
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.request', $event);
660
            }
661
662
            // ルーティング単位
663 352
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.request", $event);
664
665 936
        }, 30); // Routing(32)が解決しし, 認証判定(8)が実行される前のタイミング.
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
666
667
        // Controller Event
668 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
669
670 351
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
671 98
                return;
672
            }
673
674
675 349
            $route = $event->getRequest()->attributes->get('_route');
676
677 349
            if (is_null($route)) {
678
                return;
679
            }
680
681 349
            $app['monolog']->debug('KernelEvents::CONTROLLER '.$route);
682
683
            // 全体
684 349
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.controller', $event);
685
686 349
            if (strpos($route, 'admin') === 0) {
687
                // 管理画面
688 185
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.controller', $event);
689
            } else {
690
                // フロント画面
691 165
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.controller', $event);
692
            }
693
694
            // ルーティング単位
695 349
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.controller", $event);
696 936
        });
697
698
        // Response Event
699 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
700
701 347
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
702 98
                return;
703
            }
704
705 347
            $route = $event->getRequest()->attributes->get('_route');
706
707 347
            if (is_null($route)) {
708 1
                return;
709
            }
710
711 346
            $app['monolog']->debug('KernelEvents::RESPONSE '.$route);
712
713
            // ルーティング単位
714 346
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.response", $event);
715
716 346
            if (strpos($route, 'admin') === 0) {
717
                // 管理画面
718 187
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.response', $event);
719
            } else {
720
                // フロント画面
721 160
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.response', $event);
722
            }
723
724
            // 全体
725 346
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.response', $event);
726 936
        });
727
728
        // Exception Event
729 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function(\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
730
731 12
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
732
                return;
733
            }
734
735 12
            $route = $event->getRequest()->attributes->get('_route');
736
737 12
            if (is_null($route)) {
738
                return;
739
            }
740
741 12
            $app['monolog']->debug('KernelEvents::EXCEPTION '.$route);
742
743
            // ルーティング単位
744 12
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.exception", $event);
745
746 12
            if (strpos($route, 'admin') === 0) {
747
                // 管理画面
748 2
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.exception', $event);
749
            } else {
750
                // フロント画面
751 10
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.exception', $event);
752
            }
753
754
            // 全体
755 12
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.exception', $event);
756 936
        });
757
758
        // Terminate Event
759 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function(\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
760
761 347
            $route = $event->getRequest()->attributes->get('_route');
762
763 347
            if (is_null($route)) {
764 1
                return;
765
            }
766
767 346
            $app['monolog']->debug('KernelEvents::TERMINATE '.$route);
768
769
            // ルーティング単位
770 346
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.terminate", $event);
771
772 346
            if (strpos($route, 'admin') === 0) {
773
                // 管理画面
774 187
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.terminate', $event);
775
            } else {
776
                // フロント画面
777 160
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.terminate', $event);
778
            }
779
780
            // 全体
781 346
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.terminate', $event);
782 936
        });
783
    }
784
785 936
    public function loadPlugin()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
786
    {
787
        // プラグインディレクトリを探索.
788 936
        $basePath = __DIR__.'/../../app/Plugin';
789 936
        $finder = Finder::create()
790 936
            ->in($basePath)
791 936
            ->directories()
792 936
            ->depth(0);
793
794 936
        $finder->sortByName();
795
796
        // ハンドラ優先順位をdbから持ってきてハッシュテーブルを作成
797 936
        $priorities = array();
798 936
        $handlers = $this['orm.em']
799 936
            ->getRepository('Eccube\Entity\PluginEventHandler')
800 936
            ->getHandlers();
801 936
        foreach ($handlers as $handler) {
802
            if ($handler->getPlugin()->getEnable() && !$handler->getPlugin()->getDelFlg()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
803
804
                $priority = $handler->getPriority();
805
            } else {
806
                // Pluginがdisable、削除済みの場合、EventHandlerのPriorityを全て0とみなす
807
                $priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED;
808
            }
809 936
            $priorities[$handler->getPlugin()->getClassName()][$handler->getEvent()][$handler->getHandler()] = $priority;
810
        }
811
812
        // プラグインをロードする.
813
        // config.yml/event.ymlの定義に沿ってインスタンスの生成を行い, イベント設定を行う.
814 936
        foreach ($finder as $dir) {
815
            //config.ymlのないディレクトリは無視する
816 140
            $path = $dir->getRealPath();
817 140
            $code = $dir->getBaseName();
818
            try {
819 140
                $this['eccube.service.plugin']->checkPluginArchiveContent($path);
820
            } catch (\Eccube\Exception\PluginException $e) {
821
                $this['monolog']->warning("skip {$code} config loading. config.yml not foud or invalid.", array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
822
                    'path' =>  $path,
823
                    'original-message' => $e->getMessage()
824
                ));
825
                continue;
826
            }
827 140
            $config = $this['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml');
828
829 140
            $plugin = $this['orm.em']
830 140
                ->getRepository('Eccube\Entity\Plugin')
831 140
                ->findOneBy(array('code' => $config['code']));
832
833
            // const
834 140
            if (isset($config['const'])) {
835 1
                $this['config'] = $this->share($this->extend('config', function($eccubeConfig) use ($config) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
836 1
                    $eccubeConfig[$config['code']] = array(
837 1
                        'const' => $config['const'],
838
                    );
839
840 1
                    return $eccubeConfig;
841 1
                }));
842
            }
843
844 140
            if ($plugin && $plugin->getEnable() == Constant::DISABLED) {
845
                // プラグインが無効化されていれば読み込まない
846 1
                continue;
847
            }
848
849
            // Type: Event
850 139
            if (isset($config['event'])) {
851 139
                $class = '\\Plugin\\'.$config['code'].'\\'.$config['event'];
852 139
                $eventExists = true;
853
854 139 View Code Duplication
                if (!class_exists($class)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
855
                    $this['monolog']->warning("skip {$code} loading. event class not foud.", array(
856
                        'class' =>  $class,
857
                    ));
858
                    $eventExists = false;
859
                }
860
861 139
                if ($eventExists && file_exists($dir->getRealPath().'/event.yml')) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
862
863 139
                    $subscriber = new $class($this);
864
865 139
                    foreach (Yaml::parse(file_get_contents($dir->getRealPath().'/event.yml')) as $event => $handlers) {
866 139
                        foreach ($handlers as $handler) {
867 139
                            if (!isset($priorities[$config['event']][$event][$handler[0]])) { // ハンドラテーブルに登録されていない(ソースにしか記述されていない)ハンドラは一番後ろにする
868 139
                                $priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_LATEST;
869
                            } else {
870
                                $priority = $priorities[$config['event']][$event][$handler[0]];
871
                            }
872
                            // 優先度が0のプラグインは登録しない
873 139
                            if (\Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED != $priority) {
874 139
                                $this['eccube.event.dispatcher']->addListener($event, array($subscriber, $handler[0]), $priority);
875
                            }
876
                        }
877
                    }
878
                }
879
            }
880
            // Type: ServiceProvider
881 139
            if (isset($config['service'])) {
882
                foreach ($config['service'] as $service) {
883
                    $class = '\\Plugin\\'.$config['code'].'\\ServiceProvider\\'.$service;
884 View Code Duplication
                    if (!class_exists($class)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
885
                        $this['monolog']->warning("skip {$code} loading. service provider class not foud.", array(
886
                            'class' =>  $class,
887
                        ));
888
                        continue;
889
                    }
890 936
                    $this->register(new $class($this));
891
                }
892
            }
893
        }
894
    }
895
896
    /**
897
     * PHPUnit を実行中かどうかを設定する.
898
     *
899
     * @param boolean $testMode PHPUnit を実行中の場合 true
900
     */
901 923
    public function setTestMode($testMode) {
902 923
        $this->testMode = $testMode;
903
    }
904
905
    /**
906
     * PHPUnit を実行中かどうか.
907
     *
908
     * @return boolean PHPUnit を実行中の場合 true
909
     */
910 353
    public function isTestMode()
911
    {
912 353
        return $this->testMode;
913
    }
914
915
    /**
916
     *
917
     * データベースの接続を確認
918
     * 成功 : trueを返却
919
     * 失敗 : \Doctrine\DBAL\DBALExceptionエラーが発生( 接続に失敗した場合 )、エラー画面を表示しdie()
920
     * 備考 : app['debug']がtrueの際は処理を行わない
921
     * @return boolean true
922
     *
923
     */
924 936
    protected function checkDatabaseConnection()
925
    {
926 936
        if ($this['debug']) {
927 933
            return;
928
        }
929
        try {
930 3
            $this['db']->connect();
931
        } catch (\Doctrine\DBAL\DBALException $e) {
932
            $this['monolog']->error($e->getMessage());
933
            $this['twig.path'] = array(__DIR__.'/Resource/template/exception');
934
            $html = $this['twig']->render('error.twig', array(
935
                'error_title' => 'データーベース接続エラー',
936
                'error_message' => 'データーベースを確認してください',
937
            ));
938
            $response = new Response();
939
            $response->setContent($html);
940
            $response->setStatusCode('500');
941
            $response->headers->set('Content-Type', 'text/html');
942
            $response->send();
943
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkDatabaseConnection() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
944
        }
945 3
        return true;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
946
    }
947
948
    /**
949
     * Config ファイルをパースし、連想配列を返します.
950
     *
951
     * $config_name.yml ファイルをパースし、連想配列を返します.
952
     * $config_name.php が存在する場合は、 PHP ファイルに記述された連想配列を使用します。
953
     *
954
     * @param string $config_name Config 名称
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
955
     * @param array $configAll Config の連想配列
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
956
     * @param boolean $wrap_key Config の連想配列に config_name のキーを生成する場合 true, デフォルト false
0 ignored issues
show
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
957
     * @param string $ymlPath config yaml を格納したディレクトリ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 5 spaces after parameter name; 1 found
Loading history...
958
     * @param string $distPath config yaml dist を格納したディレクトリ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
959
     * @return Application
960
     */
961 939
    public function parseConfig($config_name, array &$configAll, $wrap_key = false, $ymlPath = null, $distPath = null)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
962
    {
963 939
        $ymlPath = $ymlPath ? $ymlPath : __DIR__.'/../../app/config/eccube';
964 939
        $distPath = $distPath ? $distPath : __DIR__.'/../../src/Eccube/Resource/config';
965 939
        $config = array();
966 939
        $config_php = $ymlPath.'/'.$config_name.'.php';
967 939
        if (!file_exists($config_php)) {
968 939
            $config_yml = $ymlPath.'/'.$config_name.'.yml';
969 939
            if (file_exists($config_yml)) {
970 939
                $config = Yaml::parse(file_get_contents($config_yml));
971 939
                $config = empty($config) ? array() : $config;
972 939 View Code Duplication
                if (isset($this['output_config_php']) && $this['output_config_php']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
973 939
                    file_put_contents($config_php, sprintf('<?php return %s', var_export($config, true)).';');
974
                }
975
            }
976
        } else {
977
            $config = require $config_php;
978
        }
979
980 939
        $config_dist = array();
981 939
        $config_php_dist = $distPath.'/'.$config_name.'.dist.php';
982 939
        if (!file_exists($config_php_dist)) {
983 939
            $config_yml_dist = $distPath.'/'.$config_name.'.yml.dist';
984 939
            if (file_exists($config_yml_dist)) {
985 939
                $config_dist = Yaml::parse(file_get_contents($config_yml_dist));
986 939 View Code Duplication
                if (isset($this['output_config_php']) && $this['output_config_php']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
987 939
                    file_put_contents($config_php_dist, sprintf('<?php return %s', var_export($config_dist, true)).';');
988
                }
989
            }
990
        } else {
991
            $config_dist = require $config_php_dist;
992
        }
993
994 939
        if ($wrap_key) {
995 939
            $configAll = array_replace_recursive($configAll, array($config_name => $config_dist), array($config_name => $config));
996
        } else {
997 939
            $configAll = array_replace_recursive($configAll, $config_dist, $config);
998
        }
999 939
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1000
    }
1001
}
1002