Failed Conditions
Push — experimental/3.1 ( 47a5a1...b65b3f )
by Yangsin
141:46 queued 135:28
created

InstallApplication::__construct()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 99
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 48
CRAP Score 11.353

Importance

Changes 0
Metric Value
cc 11
eloc 59
nc 5
nop 1
dl 0
loc 99
ccs 48
cts 56
cp 0.8571
crap 11.353
rs 5.2653
c 0
b 0
f 0

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\ServiceProvider\DiServiceProvider;
28
use Symfony\Component\Yaml\Yaml;
29
30
class InstallApplication extends \Silex\Application
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
31
{
32
    use \Silex\Application\FormTrait;
33
    use \Silex\Application\UrlGeneratorTrait;
34
    use \Silex\Application\MonologTrait;
35
    use \Silex\Application\SwiftmailerTrait;
36
    use \Silex\Application\SecurityTrait;
37
    use \Eccube\Application\ApplicationTrait;
38
    use \Eccube\Application\SecurityTrait;
39
    use \Eccube\Application\TwigTrait;
40
41 42
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
42
    {
43 42
        $app = $this;
44
45 42
        parent::__construct($values);
46
47 42
        $logDir = realpath(__DIR__.'/../../app/log');
48 42
        $installLog = $logDir.'/install.log';
49
50 42
        if (is_writable($logDir)) {
51 42
            if (file_exists($installLog) && !is_writable($installLog)) {
52
                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...
53
            }
54
            // install step2 でログディレクトリに書き込み権限が付与されればログ出力を開始する.
55 42
            $app->register(new \Silex\Provider\MonologServiceProvider(), array(
56 42
                'monolog.logfile' => $installLog,
57
            ));
58
        }
59
60
        // load config
61
        $app['config'] = function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
62 28
            $distPath = __DIR__.'/../../src/Eccube/Resource/config';
63
64 28
            $configConstant = array();
65 28
            $constantYamlPath = $distPath.'/constant.yml.dist';
66 28
            if (file_exists($constantYamlPath)) {
67 28
                $configConstant = Yaml::parse(file_get_contents($constantYamlPath));
68
            }
69
70 28
            $configLog = array();
71 28
            $logYamlPath = $distPath.'/log.yml.dist';
72 28
            if (file_exists($logYamlPath)) {
73 28
                $configLog = Yaml::parse(file_get_contents($logYamlPath));
74
            }
75
76 28
            $config = array_replace_recursive($configConstant, $configLog);
77
78 28
            return $config;
79
        };
80
81 42
        $distPath = __DIR__.'/../../src/Eccube/Resource/config';
82 42
        $config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist'));
83 42
        if (!empty($config_dist['timezone'])) {
84 42
            date_default_timezone_set($config_dist['timezone']);
85
        }
86
87 42
        $app->register(new \Silex\Provider\SessionServiceProvider());
88 42
        $app->register(new \Silex\Provider\TwigServiceProvider(), array(
89 42
            'twig.path' => array(__DIR__.'/Resource/template/install'),
90
            'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'),
91
        ));
92
93 42
        $this->register(new \Silex\Provider\FormServiceProvider());
94 42
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
95
96 42
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
97 42
            'locale' => 'ja',
98
        ));
99
        $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 42
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
101
102 42
            $r = new \ReflectionClass('Symfony\Component\Validator\Validation');
103 42
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
104 42
            if (file_exists($file)) {
105 42
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
106
            }
107
108 42
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
109 42
            if (file_exists($file)) {
110
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
111
            }
112
113 42
            $translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']);
114
115 42
            return $translator;
116 42
        });
117
118 42
        $app->mount('', new ControllerProvider\InstallControllerProvider());
0 ignored issues
show
Documentation introduced by
new \Eccube\ControllerPr...allControllerProvider() is of type object<Eccube\Controller...tallControllerProvider>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
119 42
        $app->register(new ServiceProvider\InstallServiceProvider());
120 42
        $app->register(new \Silex\Provider\CsrfServiceProvider());
121
122 42
        $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...
123
            if ($code === 404) {
124
                return $app->redirect($app->url('install'));
125
            } elseif ($app['debug']) {
126
                return;
127
            }
128
129
            return $app['twig']->render('error.twig', array(
130
                'error' => 'エラーが発生しました.',
131
            ));
132 42
        });
133
134 42
        $app->register(new DiServiceProvider(), [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
135 42
            'eccube.di.dirs' => [__DIR__.'/Form/Type/Install'],
136
            'eccube.di.generator.dir' => __DIR__.'/../../app/cache/provider',
137
            'eccube.di.generator.class' => 'InstallServiceProviderCache'
138
        ]);
139
    }
140
}
141