InstallApplication::__construct()   C
last analyzed

Complexity

Conditions 11
Paths 5

Size

Total Lines 94
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 48.114

Importance

Changes 0
Metric Value
cc 11
eloc 55
nc 5
nop 1
dl 0
loc 94
rs 5.2653
c 0
b 0
f 0
ccs 14
cts 43
cp 0.3256
crap 48.114

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 Symfony\Component\Yaml\Yaml;
28
29
class InstallApplication extends ApplicationTrait
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
30
{
31 42
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
32
    {
33 42
        $app = $this;
34
35
        parent::__construct($values);
36
37
        $logDir = realpath(__DIR__.'/../../app/log');
38 42
        $installLog = $logDir.'/install.log';
39
40
        if (is_writable($logDir)) {
41
            if (file_exists($installLog) && !is_writable($installLog)) {
42
                die($installLog . ' の書込権限を変更して下さい。');
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() 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...
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
43 28
            }
44
            // install step2 でログディレクトリに書き込み権限が付与されればログ出力を開始する.
45 28
            $app->register(new \Silex\Provider\MonologServiceProvider(), array(
46 28
                'monolog.logfile' => $installLog,
47
            ));
48
        }
49
50
        // load config
51 28
        $app['config'] = $app->share(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
52 28
            $distPath = __DIR__.'/../../src/Eccube/Resource/config';
53
54
            $configConstant = array();
55
            $constantYamlPath = $distPath.'/constant.yml.dist';
56
            if (file_exists($constantYamlPath)) {
57
                $configConstant = Yaml::parse(file_get_contents($constantYamlPath));
58
            }
59 28
60
            $configLog = array();
61
            $logYamlPath = $distPath.'/log.yml.dist';
62 42
            if (file_exists($logYamlPath)) {
63
                $configLog = Yaml::parse(file_get_contents($logYamlPath));
64 42
            }
65
66
            $config = array_replace_recursive($configConstant, $configLog);
67
68
            return $config;
69
        });
70
71 42
        $distPath = __DIR__.'/../../src/Eccube/Resource/config';
72 42
        $config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist'));
73
        if (!empty($config_dist['timezone'])) {
74
            date_default_timezone_set($config_dist['timezone']);
75
        }
76
77
        $app->register(new \Silex\Provider\SessionServiceProvider());
78
79
        $app->register(new \Silex\Provider\TwigServiceProvider(), array(
80
            'twig.path' => array(__DIR__.'/Resource/template/install'),
81
            'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'),
82
        ));
83
84
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
85
        $this->register(new \Silex\Provider\FormServiceProvider());
86
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
87
88
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
89
            'locale' => 'ja',
90
        ));
91
        $app['translator'] = $app->share($app->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...
92
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
93
94
            $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
95
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
96
            if (file_exists($file)) {
97
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
98 37
            }
99
100
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
101
            if (file_exists($file)) {
102
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
103
            }
104
105
            $translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']);
106
107
            return $translator;
108
        }));
109
110
        $app->mount('', new ControllerProvider\InstallControllerProvider());
111
        $app->register(new ServiceProvider\InstallServiceProvider());
112
113
        $app->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...
114
            if ($code === 404) {
115
                return $app->redirect($app->url('install'));
116
            } elseif ($app['debug']) {
117
                return;
118
            }
119
120
            return $app['twig']->render('error.twig', array(
121
                'error' => 'エラーが発生しました.',
122
            ));
123
        });
124
    }
125
}
126