PluginGenerator::createFilesAndFolders()   F
last analyzed

Complexity

Conditions 34
Paths > 20000

Size

Total Lines 304
Code Lines 220

Duplication

Lines 113
Ratio 37.17 %

Code Coverage

Tests 176
CRAP Score 35.5852

Importance

Changes 0
Metric Value
cc 34
eloc 220
nc 141557760
nop 2
dl 113
loc 304
ccs 176
cts 198
cp 0.8889
crap 35.5852
rs 2
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
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Command\PluginCommand;
26
27
use Eccube\Common\Constant;
28
use Symfony\Component\Filesystem\Filesystem;
29
use Symfony\Component\Yaml\Yaml;
30
use Eccube\Entity\Plugin;
31
use Eccube\Entity\PluginEventHandler;
32
use Eccube\Command\PluginCommand\AbstractPluginGenerator;
33
34
class PluginGenerator extends AbstractPluginGenerator
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
35
{
36
37
    /**
38
     *
39
     * @var array
40
     */
41
    private $hookPoints = null;
42
43
    /**
44
     *
45
     * @var array
46
     */
47
    private $events = null;
48
49 1 View Code Duplication
    protected function getHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
50
    {
51 1
        $this->output->writeln('------------------------------------------------------');
52 1
        $this->output->writeln('---Plugin Generator');
53 1
        $this->output->writeln('---[*]You can exit from Console Application, by typing ' . self::STOP_PROCESS . ' instead of typing another word.');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
54 1
        $this->output->writeln('------------------------------------------------------');
55 1
        $this->output->writeln('');
56
    }
57
58 1
    protected function initFildset()
59
    {
60 1
        $this->paramList = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
61
            'pluginName' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
62
                'no' => 1,
63
                'label' => '[+]Plugin Name: ',
64
                'value' => null,
65
                'name' => '[+]Please enter Plugin Name',
66
                'validation' => array(
67
                    'isRequired' => true,
68
                )
69 1
            ),
70
            'pluginCode' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
71
                'no' => 2,
72
                'label' => '[+]Plugin Code: ',
73
                'value' => null,
74
                'name' => '[+]Please enter Plugin Name (only pascal case letters numbers are allowed)',
75
                'validation' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
76
                    'isRequired' => true,
77
                    'patern' => '/^[A-Z][0-9a-zA-Z]*$/'
78
                )
79
            ),
80
            'version' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
81
                'no' => 3,
82
                'label' => '[+]Version: ',
83
                'value' => null,
84
                'name' => '[+]Please enter version (correct format is x.y.z)',
85
                'validation' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
86
                    'isRequired' => true,
87
                    'patern' => '/^\d+.\d+.\d+$/'
88
                )
89
            ),
90
            'author' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
91
                'no' => 4,
92
                'label' => '[+]Author: ',
93
                'value' => null,
94
                'name' => '[+]Please enter author name or company',
95
                'validation' => array(
96
                    'isRequired' => true,
97
                )
98
            ),
99
            'supportFlag' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
100
                'no' => 5,
101
                'label' => '[+]Old version support: ',
102
                'value' => null,
103
                'name' => '[+]Do you want to support old versions too? [y/n]',
104
                'show' => array(1 => 'Yes' ,0 => 'No'),
0 ignored issues
show
introduced by
Add a single space after each comma delimiter
Loading history...
105
                'validation' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
106
                    'isRequired' => true,
107
                    'choice' => array('y' => 1, 'n' => 0)
108
                )
109
            ),
110
            'events' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
111
                'no' => 6,
112
                'label' => '[+]Site events: ',
113
                'value' => array(),
114
                'name' => '[+]Please enter site events(you can find documentation here http://www.ec-cube.net/plugin/)',
115
                'validation' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
116
                    'isRequired' => false,
117
                    'inArray' => 'getEvents'
118
                )
119
            ),
120
            'hookPoints' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
121 1
                'no' => 7,
122 1
                'label' => '[+]Hook points: ',
123
                'value' => array(),
124 1
                'name' => '[+]Please enter hook point, sample:front.cart.up.initialize',
125
                'validation' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
126
                    'isRequired' => false,
127 1
                    'inArray' => $this->getHookPoints()
128
                )
129
            )
130
        );
131
    }
132
133 1
    private function getHookPoints()
134
    {
135 1
        if ($this->hookPoints === null) {
136 1
            $Ref = new \ReflectionClass('\Eccube\Event\EccubeEvents');
137 1
            $this->hookPoints = array_flip($Ref->getConstants());
138
        }
139 1
        return $this->hookPoints;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
140
    }
141
142 1
    protected function getEvents()
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
143
    {
144 1
        if (!isset($this->paramList['supportFlag']['value'])) {
145
            return array();
146
        }
147 1
        if ($this->events === null) {
148 1
            $this->events = array();
149 1
            $routeEvents = array();
150 1
            if ($this->paramList['supportFlag']['value']) {
151 1
                $this->events = include $this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/eventsList.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
152 1
                $routeEvents['eccube.event.controller.__route__.before'] = 'Controller__route__Before';
153 1
                $routeEvents['eccube.event.controller.__route__.after'] = 'Controller__route__After';
154 1
                $routeEvents['eccube.event.controller.__route__.finish'] = 'Controller__route__Finish';
155 1
                $routeEvents['eccube.event.render.__route__.before'] = 'Render__route__Before';
156
            }
157 1
            $this->events += include $this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/eventsListNew.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
158
159 1
            $routeEvents['eccube.event.route.__route__.request'] = 'Route__route__Request';
160 1
            $routeEvents['eccube.event.route.__route__.controller'] = 'Route__route__Controller';
161 1
            $routeEvents['eccube.event.route.__route__.response'] = 'Route__route__Response';
162 1
            $routeEvents['eccube.event.route.__route__.exception'] = 'Route__route__Exception';
163 1
            $routeEvents['eccube.event.route.__route__.terminate'] = 'Route__route__Terminate';
164 1
            $allRoutes = array();
165
166 1
            $controllers = $this->app['controllers'];
167 1
            $collection = $controllers->flush();
168 1
            foreach ($collection as $eventName => $dummy) {
169 1
                $allRoutes[] = $eventName;
170
            }
171
172 1
            $routes = $this->app['routes']->all();
173
174 1
            foreach ($routes as $eventName => $dummy) {
175 1
                $allRoutes[] = $eventName;
176
            }
177
178 1
            foreach ($allRoutes as $eventName) {
179 1
                $eventOnFunc = join(array_map('ucfirst', explode('_', strtolower($eventName))));
180
181 1
                foreach ($routeEvents as $keys => $node) {
182 1
                    $this->events[str_replace('__route__', $eventName, $keys)] = str_replace('__route__', $eventOnFunc, $node);
183
                }
184
            }
185
        }
186
187 1
        return $this->events;
188
    }
189
190 1
    protected function start()
191
    {
192 1
        $pluginCode = $this->paramList['pluginCode']['value'];
193
194 1
        $Plugin = $this->app['eccube.repository.plugin']->findOneBy(array('code' => $pluginCode));
195 1
        if ($Plugin) {
196
            $this->exitGenerator('<error>Plugin with this name already exists</error>');
197
            return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
198
        }
199 1
        $this->createFilesAndFolders($pluginCode, $this->paramList);
200 1
        $this->createDbRecords($pluginCode, $this->paramList);
201 1
        $this->exitGenerator('Plugin was created successfully');
202
    }
203
204 1
    private function createFilesAndFolders($code, $paramList)
205
    {
206
        $fsList = array(
207 1
            'dir' => array(),
208
            'file' => array(),
209
        );
210
211
        // config.ymlを作成
212 1
        $config = array();
213 1
        $config['name'] = $paramList['pluginName']['value'];
214 1
        $config['code'] = $code;
215 1
        $config['version'] = $paramList['version']['value'];
216 1
        if (!empty($paramList['hookPoints']['value'])) {
217 1
            $config['event'] = $code . 'Event';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
218
        }
219 1
        $config['service'] = array($code . 'ServiceProvider');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
220
221 1
        $codePath = $this->app['config']['root_dir'] . '/app/Plugin/' . $code;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
222
223 1
        $file = new Filesystem();
224 1
        $file->mkdir($codePath);
225 1
        if (is_dir($codePath)) {
226 1
            $fsList['dir'][$codePath] = true;
227
        } else {
228
            $fsList['dir'][$codePath] = false;
229
        }
230
231 1
        $srcPath = $codePath . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
232 1
        file_put_contents($srcPath, Yaml::dump($config));
233 1 View Code Duplication
        if (is_file($srcPath)) {
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...
234 1
            $fsList['file'][$srcPath] = true;
235
        } else {
236
            $fsList['file'][$srcPath] = false;
237
        }
238
239 1
        $author = $paramList['pluginName']['value'];
240 1
        $year = date('Y');
241
242
        // PluginManager
243 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/PluginManager.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
244 1
        $from = '/\[code\]/';
245 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
246 1
        $from = '/\[author\]/';
247 1
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
248 1
        $from = '/\[year\]/';
249 1
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
250
251 1
        $srcPath = $codePath . '/PluginManager.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
252 1
        file_put_contents($srcPath, $pluginFileAfter);
253 1 View Code Duplication
        if (is_file($srcPath)) {
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...
254 1
            $fsList['file'][$srcPath] = true;
255
        } else {
256
            $fsList['file'][$srcPath] = false;
257
        }
258
259
        // ServiceProvider
260 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ServiceProvider.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
261 1
        $from = '/\[code\]/';
262 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
263 1
        $from = '/\[author\]/';
264 1
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
265 1
        $from = '/\[year\]/';
266 1
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
267
268 1
        $file->mkdir($codePath . '/ServiceProvider');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
269 1 View Code Duplication
        if (is_dir($codePath . '/ServiceProvider')) {
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
Concat operator must not be surrounded by spaces
Loading history...
270 1
            $fsList['dir'][$codePath . '/ServiceProvider'] = true;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
271
        } else {
272
            $fsList['dir'][$codePath . '/ServiceProvider'] = false;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
273
        }
274
275 1
        $srcPath = $codePath . '/ServiceProvider/' . $code . 'ServiceProvider.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
276 1
        file_put_contents($srcPath, $pluginFileAfter);
277 1 View Code Duplication
        if (is_file($srcPath)) {
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...
278 1
            $fsList['file'][$srcPath] = true;
279
        } else {
280
            $fsList['file'][$srcPath] = false;
281
        }
282
283
        // ConfigController
284 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ConfigController.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
285 1
        $from = '/\[code\]/';
286 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
287 1
        $from = '/\[author\]/';
288 1
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
289 1
        $from = '/\[year\]/';
290 1
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
291 1
        $from = '/\[code_name\]/';
292 1
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
293
294 1
        $file->mkdir($codePath . '/Controller');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
295 1 View Code Duplication
        if (is_dir($codePath . '/Controller')) {
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
Concat operator must not be surrounded by spaces
Loading history...
296 1
            $fsList['dir'][$codePath . '/Controller'] = true;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
297
        } else {
298
            $fsList['dir'][$codePath . '/Controller'] = false;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
299
        }
300
301 1
        $srcPath = $codePath . '/Controller/ConfigController.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
302 1
        file_put_contents($srcPath, $pluginFileAfter);
303 1 View Code Duplication
        if (is_file($srcPath)) {
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...
304 1
            $fsList['file'][$srcPath] = true;
305
        } else {
306
            $fsList['file'][$srcPath] = false;
307
        }
308
309
        // Controller
310 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/Controller.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
311 1
        $from = '/\[code\]/';
312 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
313 1
        $from = '/\[author\]/';
314 1
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
315 1
        $from = '/\[year\]/';
316 1
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
317 1
        $from = '/\[code_name\]/';
318 1
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
319
320 1
        $srcPath = $codePath . '/Controller/' . $code . 'Controller.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
321 1
        file_put_contents($srcPath, $pluginFileAfter);
322 1 View Code Duplication
        if (is_file($srcPath)) {
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...
323 1
            $fsList['file'][$srcPath] = true;
324
        } else {
325
            $fsList['file'][$srcPath] = false;
326
        }
327
328
        // Form
329 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ConfigType.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
330 1
        $from = '/\[code\]/';
331 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
332 1
        $from = '/\[author\]/';
333 1
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
334 1
        $from = '/\[year\]/';
335 1
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
336 1
        $from = '/\[code_name\]/';
337 1
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
338
339 1
        $file->mkdir($codePath . '/Form/Type');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
340 1 View Code Duplication
        if (is_dir($codePath . '/Form/Type')) {
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
Concat operator must not be surrounded by spaces
Loading history...
341 1
            $fsList['dir'][$codePath . '/Form/Type'] = true;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
342
        } else {
343
            $fsList['dir'][$codePath . '/Form/Type'] = false;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
344
        }
345
346 1
        $srcPath = $codePath . '/Form/Type/' . $code . 'ConfigType.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
347 1
        file_put_contents($codePath . '/Form/Type/' . $code . 'ConfigType.php', $pluginFileAfter);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
348 1 View Code Duplication
        if (is_file($srcPath)) {
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...
349 1
            $fsList['file'][$srcPath] = true;
350
        } else {
351
            $fsList['file'][$srcPath] = false;
352
        }
353
354
        // Twig
355 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/config.twig');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
356 1
        $from = '/\[code\]/';
357 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
358
359 1
        $file->mkdir($codePath . '/Resource/template/admin');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
360 1 View Code Duplication
        if (is_dir($codePath . '/Resource/template/admin')) {
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
Concat operator must not be surrounded by spaces
Loading history...
361 1
            $fsList['dir'][$codePath . '/Resource/template/admin'] = true;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
362
        } else {
363
            $fsList['dir'][$codePath . '/Resource/template/admin'] = false;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
364
        }
365
366 1
        $srcPath = $codePath . '/Resource/template/admin/config.twig';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
367 1
        file_put_contents($srcPath, $pluginFileAfter);
368 1 View Code Duplication
        if (is_file($srcPath)) {
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...
369 1
            $fsList['file'][$srcPath] = true;
370
        } else {
371
            $fsList['file'][$srcPath] = false;
372
        }
373
374
        // index.twig
375 1
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/index.twig');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
376 1
        $from = '/\[code\]/';
377 1
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
378
379 1
        $file->mkdir($codePath . '/Resource/template/admin');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
380 1 View Code Duplication
        if (is_dir($codePath . '/Resource/template/admin')) {
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
Concat operator must not be surrounded by spaces
Loading history...
381 1
            $fsList['dir'][$codePath . '/Resource/template/admin'] = true;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
382
        } else {
383
            $fsList['dir'][$codePath . '/Resource/template/admin'] = false;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
384
        }
385
386 1
        $srcPath = $codePath . '/Resource/template/index.twig';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
387 1
        file_put_contents($srcPath, $pluginFileAfter);
388 1 View Code Duplication
        if (is_file($srcPath)) {
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...
389 1
            $fsList['file'][$srcPath] = true;
390
        } else {
391
            $fsList['file'][$srcPath] = false;
392
        }
393
394 1
        $onFunctions = array();
395 1
        $onEvents = array();
396
397
        //イベント
398 1
        $events = $paramList['events']['value'];
399 1
        if (count($events) > 0) {
400 1
            foreach ($events as $eventKey => $eventConst) {
401 1
                $onEvents[$eventKey] = array(array('on' . $eventConst . ', NORMAL'));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
402 1
                $onFunctions[] = 'on' . $eventConst;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
403
            }
404
        }
405
406
        //フックポイント
407 1
        $hookPoints = $paramList['hookPoints']['value'];
408 1
        if (count($hookPoints)) {
409 1
            foreach ($hookPoints as $hookKey => $hookConst) {
410 1
                $onName = 'on' . join(array_map('ucfirst', explode('_', strtolower($hookConst))));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
411 1
                $onEvents[$hookKey] = array(array($onName . ', NORMAL'));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
412 1
                $onFunctions[] = $onName;
413
            }
414
        }
415
416 1
        if (count($onEvents)) {
417 1
            $srcPath = $codePath . '/event.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
418 1
            file_put_contents($srcPath, str_replace('\'', '', Yaml::dump($onEvents)));
419 1 View Code Duplication
            if (is_file($srcPath)) {
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...
420 1
                $fsList['file'][$srcPath] = true;
421
            } else {
422
                $fsList['file'][$srcPath] = false;
423
            }
424
425 1
            $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/EventHookpoint2.php');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
426
427
            // Event
428 1
            $from = '/\[code\]/';
429 1
            $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
430 1
            $from = '/\[author\]/';
431 1
            $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
432 1
            $from = '/\[year\]/';
433 1
            $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
434
435 1
            $functions = '';
436 1
            foreach ($onFunctions as $functionName) {
437 1
                $functions .= "    public function " . $functionName . "(EventArgs \$event)\n    {\n    }\n\n";
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
438
            }
439 1
            $from = '/\[hookpoint_function\]/';
440 1
            $pluginFileAfter = preg_replace($from, $functions, $pluginFileAfter);
441 1
            $srcPath = $codePath . '/' . $code . 'Event.php';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
442 1
            file_put_contents($srcPath, $pluginFileAfter);
443 1 View Code Duplication
            if (is_file($srcPath)) {
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...
444 1
                $fsList['file'][$srcPath] = true;
445
            } else {
446
                $fsList['file'][$srcPath] = false;
447
            }
448
        }
449
450
        // config.ymlを再作成
451 1
        $config = array();
452 1
        $config['name'] = $paramList['pluginName']['value'];
453 1
        $config['code'] = $code;
454 1
        $config['version'] = $paramList['version']['value'];
455 1
        $config['event'] = $code . 'Event';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
456 1
        $config['service'] = array($code . 'ServiceProvider');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
457 1
        $srcPath = $codePath . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
458 1
        file_put_contents($srcPath, Yaml::dump($config));
459 1 View Code Duplication
        if (is_file($srcPath)) {
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...
460 1
            $fsList['file'][$srcPath] = true;
461
        } else {
462
            $fsList['file'][$srcPath] = false;
463
        }
464
465
        // LICENSE
466 1
        $srcPath = $codePath . '/LICENSE';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
467 1
        $file->copy($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/LICENSE', $srcPath);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
468 1 View Code Duplication
        if (is_file($srcPath)) {
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...
469 1
            $fsList['file'][$srcPath] = true;
470
        } else {
471
            $fsList['file'][$srcPath] = false;
472
        }
473
474 1
        $dirFileNg = array();
475 1
        $dirFileOk = array();
476 1 View Code Duplication
        foreach ($fsList['dir'] as $path => $flag) {
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...
477 1
            if ($flag) {
478 1
                $dirFileOk[] = $path;
479
            } else {
480 1
                $dirFileNg[] = $path;
481
            }
482
        }
483 1 View Code Duplication
        foreach ($fsList['file'] as $path => $flag) {
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...
484 1
            if ($flag) {
485 1
                $dirFileOk[] = $path;
486
            } else {
487 1
                $dirFileNg[] = $path;
488
            }
489
        }
490 1
        $this->output->writeln('');
491 1
        $this->output->writeln('[+]File system');
492 1 View Code Duplication
        if (!empty($dirFileOk)) {
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...
493 1
            $this->output->writeln('');
494 1
            $this->output->writeln(' this files and folders were created.');
495 1
            foreach ($dirFileOk as $path) {
496 1
                $this->output->writeln('<info> - ' . $path . '</info>');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
497
            }
498
        }
499
500 1 View Code Duplication
        if (!empty($dirFileNg)) {
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...
501
            $this->output->writeln('');
502
            $this->output->writeln(' this files and folders was not created.');
503
            foreach ($dirFileOk as $path) {
504
                $this->output->writeln('<error> - ' . $path . '</error>');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
505
            }
506
        }
507
    }
508
509 1
    private function createDbRecords($code, $paramList)
510
    {
511
        // DB登録
512 1
        $Plugin = new Plugin();
513 1
        $Plugin->setName($paramList['pluginName']['value']);
514 1
        $Plugin->setCode($code);
515 1
        $Plugin->setClassName('');
516 1
        $Plugin->setVersion($paramList['version']['value']);
517 1
        $Plugin->setEnable(Constant::DISABLED);
518 1
        $Plugin->setSource(0);
519 1
        $Plugin->setDelFlg(Constant::DISABLED);
520
521 1
        $this->app['orm.em']->persist($Plugin);
522 1
        $this->app['orm.em']->flush($Plugin);
523
524 1
        $this->output->writeln('');
525 1
        $this->output->writeln('[+]Database');
526 1
        if ($Plugin->getId()) {
527 1
            $this->output->writeln('<info> Plugin information was added to table [DB.Plugin] (id=' . $Plugin->getId() . ')</info>');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
528
        } else {
529
            $this->output->writeln('<error> there was a problem inserting plugin information to table [DB.Plugin] (id=' . $Plugin->getId() . ')</error>');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
530
        }
531
532 1
        $hookPoints = $paramList['hookPoints']['value'];
533 1
        if (empty($hookPoints)) {
534
            return;
535
        }
536
537 1
        $eventCount = 0;
538 1
        foreach ($hookPoints as $hookKey => $hookConst) {
539 1
            $PluginEventHandler = new PluginEventHandler();
540 1
            $functionName = 'on' . join(array_map('ucfirst', explode('_', strtolower($hookConst))));
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
541 1
            $PluginEventHandler->setPlugin($Plugin)
542 1
                ->setEvent($hookKey)
543 1
                ->setPriority($this->app['eccube.repository.plugin_event_handler']->calcNewPriority($hookKey, $functionName))
544 1
                ->setHandler($functionName)
545 1
                ->setHandlerType('NORMAL')
546 1
                ->setDelFlg(Constant::DISABLED);
547 1
            $this->app['orm.em']->persist($PluginEventHandler);
548 1
            $eventCount++;
549
        }
550 1
        $this->app['orm.em']->flush();
551 1
        if ($eventCount) {
552 1
            $this->output->writeln('');
553 1
            $this->output->writeln('<info> Plugin information was added to table [DB.PluginEventHandler] (inserts number=' . $eventCount . ') </info>');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
554
        }
555
    }
556
}
557