Completed
Push — experimental/3.1 ( 3ded70...5f55e6 )
by chihiro
18:23 queued 18:05
created

InstallApplication::__construct()   C

Complexity

Conditions 11
Paths 5

Size

Total Lines 103
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 51
CRAP Score 11.3016

Importance

Changes 0
Metric Value
cc 11
eloc 61
nc 5
nop 1
dl 0
loc 103
ccs 51
cts 59
cp 0.8644
crap 11.3016
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
29
class InstallApplication extends \Silex\Application
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
30
{
31
    use \Silex\Application\FormTrait;
32
    use \Silex\Application\UrlGeneratorTrait;
33
    use \Silex\Application\MonologTrait;
34
    use \Silex\Application\SwiftmailerTrait;
35
    use \Silex\Application\SecurityTrait;
36
    use \Eccube\Application\ApplicationTrait;
37
    use \Eccube\Application\SecurityTrait;
38
    use \Eccube\Application\TwigTrait;
39
40 42
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
41
    {
42 42
        $app = $this;
43
44 42
        parent::__construct($values);
45
46 42
        $logDir = realpath(__DIR__.'/../../app/log');
47 42
        $installLog = $logDir.'/install.log';
48
49 42
        if (is_writable($logDir)) {
50 42
            if (file_exists($installLog) && !is_writable($installLog)) {
51
                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...
52
            }
53
            // install step2 でログディレクトリに書き込み権限が付与されればログ出力を開始する.
54 42
            $app->register(new \Silex\Provider\MonologServiceProvider(), array(
55 42
                'monolog.logfile' => $installLog,
56
            ));
57
        }
58
59
        // load config
60
        $app['config'] = function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
61 28
            $distPath = __DIR__.'/../../src/Eccube/Resource/config';
62
63 28
            $configConstant = array();
64 28
            $constantYamlPath = $distPath.'/constant.php';
65 28
            if (file_exists($constantYamlPath)) {
66 28
                $configConstant = require $constantYamlPath;
67
            }
68
69 28
            $configLog = array();
70 28
            $logYamlPath = $distPath.'/log.php';
71 28
            if (file_exists($logYamlPath)) {
72 28
                $configLog = require $logYamlPath;
73
            }
74
75 28
            $config = array_replace_recursive($configConstant, $configLog);
76
77 28
            return $config;
78
        };
79
80 42
        $distPath = __DIR__.'/../../src/Eccube/Resource/config';
81 42
        $config_dist = require $distPath.'/config.php';
82 42
        if (!empty($config_dist['timezone'])) {
83 42
            date_default_timezone_set($config_dist['timezone']);
84
        }
85
86 42
        $app->register(new \Silex\Provider\SessionServiceProvider());
87 42
        $app->register(new \Silex\Provider\TwigServiceProvider(), array(
88 42
            'twig.path' => array(__DIR__.'/Resource/template/install'),
89
            'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'),
90
        ));
91
92 42
        $this->register(new \Silex\Provider\FormServiceProvider());
93 42
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
94
95 42
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
96 42
            'locale' => 'ja',
97
        ));
98
        $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...
99 42
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
100
101 42
            $r = new \ReflectionClass('Symfony\Component\Validator\Validation');
102 42
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
103 42
            if (file_exists($file)) {
104 42
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
105
            }
106
107 42
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
108 42
            if (file_exists($file)) {
109
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
110
            }
111
112 42
            $translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']);
113
114 42
            return $translator;
115 42
        });
116
117 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...
118 42
        $app->register(new ServiceProvider\InstallServiceProvider());
119 42
        $app->register(new \Silex\Provider\CsrfServiceProvider());
120
121 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...
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 42
        });
132
133 42
        $app->register(new DiServiceProvider(), [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
134 42
            'eccube.di.scanners' => [
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
135 42
                new \Eccube\Di\Scanner\FormTypeScanner([
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
136 42
                    __DIR__.'/Form/Type/Install'
137
                ])
138
            ],
139
            'eccube.di.generator.dir' => __DIR__.'/../../app/cache/provider',
140 42
            'eccube.di.generator.class' => 'InstallServiceProviderCache'
141
        ]);
142
    }
143
}
144