Failed Conditions
Pull Request — master (#1543)
by Tsuyoshi
489:47 queued 481:38
created

InstallApplication::__construct()   D

Complexity

Conditions 10
Paths 6

Size

Total Lines 99
Code Lines 59

Duplication

Lines 13
Ratio 13.13 %

Code Coverage

Tests 16
CRAP Score 38.6973

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 99
ccs 16
cts 47
cp 0.3404
rs 4.8514
cc 10
eloc 59
nc 6
nop 1
crap 38.6973

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
    public $package;
32
    public $rootDir;
33
34 40
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
35
    {
36 View Code Duplication
        if (\Phar::running(false)) {
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...
37
            // phar
38
            $this->package = 'phar';
39
            $this->rootDir = dirname(\Phar::running(false));
40
        } elseif (file_exists(__DIR__.'/../../../../../vendor/ec-cube/ec-cube')) {
41
            // composer
42
            $this->package = 'composer';
43
            $this->rootDir = __DIR__.'/../../../../..';
44
        } else {
45
            // other
46 40
            $this->package = 'general';
47 40
            $this->rootDir = __DIR__.'/../..';
48
        }
49
50 40
        $app = $this;
51
52
        parent::__construct($values);
53
54
        $app->register(new \Silex\Provider\MonologServiceProvider(), array(
55 40
            'monolog.logfile' => $this->rootDir.'/app/log/install.log',
56
        ));
57
58
        // load config
59
        $app['config'] = $app->share(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
60 27
            $distPath = __DIR__.'/Resource/config';
61
62 27
            $configConstant = array();
63 27
            $constantYamlPath = $distPath.'/constant.yml.dist';
64
            if (file_exists($constantYamlPath)) {
65
                $configConstant = Yaml::parse(file_get_contents($constantYamlPath));
66
            }
67
68 27
            $configLog = array();
69 27
            $logYamlPath = $distPath.'/log.yml.dist';
70
            if (file_exists($logYamlPath)) {
71
                $configLog = Yaml::parse(file_get_contents($logYamlPath));
72
            }
73
74
            $config = array_replace_recursive($configConstant, $configLog);
75
76 27
            return $config;
77
        });
78
79 40
        $distPath = __DIR__.'/Resource/config';
80
        $config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist'));
81 40
        if (!empty($config_dist['timezone'])) {
82
            date_default_timezone_set($config_dist['timezone']);
83
        }
84
85
        $app->register(new \Silex\Provider\SessionServiceProvider());
86
87
        $app->register(new \Silex\Provider\TwigServiceProvider(), array(
88 40
            'twig.path' => array(__DIR__.'/Resource/template/install'),
89 40
            'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'),
90
        ));
91
92
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
93
        $this->register(new \Silex\Provider\FormServiceProvider());
94
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
95
96
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
97
            'locale' => 'ja',
98
        ));
99
        $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...
100
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
101
102
            $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
103
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
104
            if (file_exists($file)) {
105
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
106
            }
107
108
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
109
            if (file_exists($file)) {
110
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
111
            }
112
113
            $translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']);
114
115 36
            return $translator;
116
        }));
117
118
        $app->mount('', new ControllerProvider\InstallControllerProvider());
119
        $app->register(new ServiceProvider\InstallServiceProvider());
120
121
        $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...
122
            if ($code === 404) {
123
                return $app->redirect($app->url('install'));
124
            } elseif ($app['debug']) {
125
                return;
126
            }
127
128
            return $app['twig']->render('error.twig', array(
129
                'error' => 'エラーが発生しました.',
130
            ));
131
        });
132
    }
133
}
134