| Conditions | 34 |
| Paths | > 20000 |
| Total Lines | 304 |
| Code Lines | 220 |
| Lines | 113 |
| Ratio | 37.17 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 204 | private function createFilesAndFolders($code, $paramList) |
||
| 205 | { |
||
| 206 | $fsList = array( |
||
| 207 | 'dir' => array(), |
||
| 208 | 'file' => array(), |
||
| 209 | ); |
||
| 210 | |||
| 211 | // config.ymlを作成 |
||
| 212 | $config = array(); |
||
| 213 | $config['name'] = $paramList['pluginName']['value']; |
||
| 214 | $config['code'] = $code; |
||
| 215 | $config['version'] = $paramList['version']['value']; |
||
| 216 | if (!empty($paramList['hookPoints']['value'])) { |
||
| 217 | $config['event'] = $code . 'Event'; |
||
| 218 | } |
||
| 219 | $config['service'] = array($code . 'ServiceProvider'); |
||
| 220 | |||
| 221 | $codePath = $this->app['config']['root_dir'] . '/app/Plugin/' . $code; |
||
| 222 | |||
| 223 | $file = new Filesystem(); |
||
| 224 | $file->mkdir($codePath); |
||
| 225 | if (is_dir($codePath)) { |
||
| 226 | $fsList['dir'][$codePath] = true; |
||
| 227 | } else { |
||
| 228 | $fsList['dir'][$codePath] = false; |
||
| 229 | } |
||
| 230 | |||
| 231 | $srcPath = $codePath . '/config.yml'; |
||
| 232 | file_put_contents($srcPath, Yaml::dump($config)); |
||
| 233 | View Code Duplication | if (is_file($srcPath)) { |
|
| 234 | $fsList['file'][$srcPath] = true; |
||
| 235 | } else { |
||
| 236 | $fsList['file'][$srcPath] = false; |
||
| 237 | } |
||
| 238 | |||
| 239 | $author = $paramList['pluginName']['value']; |
||
| 240 | $year = date('Y'); |
||
| 241 | |||
| 242 | // PluginManager |
||
| 243 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/PluginManager.php'); |
||
| 244 | $from = '/\[code\]/'; |
||
| 245 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 246 | $from = '/\[author\]/'; |
||
| 247 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 248 | $from = '/\[year\]/'; |
||
| 249 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 250 | |||
| 251 | $srcPath = $codePath . '/PluginManager.php'; |
||
| 252 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 253 | View Code Duplication | if (is_file($srcPath)) { |
|
| 254 | $fsList['file'][$srcPath] = true; |
||
| 255 | } else { |
||
| 256 | $fsList['file'][$srcPath] = false; |
||
| 257 | } |
||
| 258 | |||
| 259 | // ServiceProvider |
||
| 260 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ServiceProvider.php'); |
||
| 261 | $from = '/\[code\]/'; |
||
| 262 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 263 | $from = '/\[author\]/'; |
||
| 264 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 265 | $from = '/\[year\]/'; |
||
| 266 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 267 | |||
| 268 | $file->mkdir($codePath . '/ServiceProvider'); |
||
| 269 | View Code Duplication | if (is_dir($codePath . '/ServiceProvider')) { |
|
| 270 | $fsList['dir'][$codePath . '/ServiceProvider'] = true; |
||
| 271 | } else { |
||
| 272 | $fsList['dir'][$codePath . '/ServiceProvider'] = false; |
||
| 273 | } |
||
| 274 | |||
| 275 | $srcPath = $codePath . '/ServiceProvider/' . $code . 'ServiceProvider.php'; |
||
| 276 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 277 | View Code Duplication | if (is_file($srcPath)) { |
|
| 278 | $fsList['file'][$srcPath] = true; |
||
| 279 | } else { |
||
| 280 | $fsList['file'][$srcPath] = false; |
||
| 281 | } |
||
| 282 | |||
| 283 | // ConfigController |
||
| 284 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ConfigController.php'); |
||
| 285 | $from = '/\[code\]/'; |
||
| 286 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 287 | $from = '/\[author\]/'; |
||
| 288 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 289 | $from = '/\[year\]/'; |
||
| 290 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 291 | $from = '/\[code_name\]/'; |
||
| 292 | $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter); |
||
| 293 | |||
| 294 | $file->mkdir($codePath . '/Controller'); |
||
| 295 | View Code Duplication | if (is_dir($codePath . '/Controller')) { |
|
| 296 | $fsList['dir'][$codePath . '/Controller'] = true; |
||
| 297 | } else { |
||
| 298 | $fsList['dir'][$codePath . '/Controller'] = false; |
||
| 299 | } |
||
| 300 | |||
| 301 | $srcPath = $codePath . '/Controller/ConfigController.php'; |
||
| 302 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 303 | View Code Duplication | if (is_file($srcPath)) { |
|
| 304 | $fsList['file'][$srcPath] = true; |
||
| 305 | } else { |
||
| 306 | $fsList['file'][$srcPath] = false; |
||
| 307 | } |
||
| 308 | |||
| 309 | // Controller |
||
| 310 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/Controller.php'); |
||
| 311 | $from = '/\[code\]/'; |
||
| 312 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 313 | $from = '/\[author\]/'; |
||
| 314 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 315 | $from = '/\[year\]/'; |
||
| 316 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 317 | $from = '/\[code_name\]/'; |
||
| 318 | $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter); |
||
| 319 | |||
| 320 | $srcPath = $codePath . '/Controller/' . $code . 'Controller.php'; |
||
| 321 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 322 | View Code Duplication | if (is_file($srcPath)) { |
|
| 323 | $fsList['file'][$srcPath] = true; |
||
| 324 | } else { |
||
| 325 | $fsList['file'][$srcPath] = false; |
||
| 326 | } |
||
| 327 | |||
| 328 | // Form |
||
| 329 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/ConfigType.php'); |
||
| 330 | $from = '/\[code\]/'; |
||
| 331 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 332 | $from = '/\[author\]/'; |
||
| 333 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 334 | $from = '/\[year\]/'; |
||
| 335 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 336 | $from = '/\[code_name\]/'; |
||
| 337 | $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter); |
||
| 338 | |||
| 339 | $file->mkdir($codePath . '/Form/Type'); |
||
| 340 | View Code Duplication | if (is_dir($codePath . '/Form/Type')) { |
|
| 341 | $fsList['dir'][$codePath . '/Form/Type'] = true; |
||
| 342 | } else { |
||
| 343 | $fsList['dir'][$codePath . '/Form/Type'] = false; |
||
| 344 | } |
||
| 345 | |||
| 346 | $srcPath = $codePath . '/Form/Type/' . $code . 'ConfigType.php'; |
||
| 347 | file_put_contents($codePath . '/Form/Type/' . $code . 'ConfigType.php', $pluginFileAfter); |
||
| 348 | View Code Duplication | if (is_file($srcPath)) { |
|
| 349 | $fsList['file'][$srcPath] = true; |
||
| 350 | } else { |
||
| 351 | $fsList['file'][$srcPath] = false; |
||
| 352 | } |
||
| 353 | |||
| 354 | // Twig |
||
| 355 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/config.twig'); |
||
| 356 | $from = '/\[code\]/'; |
||
| 357 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 358 | |||
| 359 | $file->mkdir($codePath . '/Resource/template/admin'); |
||
| 360 | View Code Duplication | if (is_dir($codePath . '/Resource/template/admin')) { |
|
| 361 | $fsList['dir'][$codePath . '/Resource/template/admin'] = true; |
||
| 362 | } else { |
||
| 363 | $fsList['dir'][$codePath . '/Resource/template/admin'] = false; |
||
| 364 | } |
||
| 365 | |||
| 366 | $srcPath = $codePath . '/Resource/template/admin/config.twig'; |
||
| 367 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 368 | View Code Duplication | if (is_file($srcPath)) { |
|
| 369 | $fsList['file'][$srcPath] = true; |
||
| 370 | } else { |
||
| 371 | $fsList['file'][$srcPath] = false; |
||
| 372 | } |
||
| 373 | |||
| 374 | // index.twig |
||
| 375 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/index.twig'); |
||
| 376 | $from = '/\[code\]/'; |
||
| 377 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 378 | |||
| 379 | $file->mkdir($codePath . '/Resource/template/admin'); |
||
| 380 | View Code Duplication | if (is_dir($codePath . '/Resource/template/admin')) { |
|
| 381 | $fsList['dir'][$codePath . '/Resource/template/admin'] = true; |
||
| 382 | } else { |
||
| 383 | $fsList['dir'][$codePath . '/Resource/template/admin'] = false; |
||
| 384 | } |
||
| 385 | |||
| 386 | $srcPath = $codePath . '/Resource/template/index.twig'; |
||
| 387 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 388 | View Code Duplication | if (is_file($srcPath)) { |
|
| 389 | $fsList['file'][$srcPath] = true; |
||
| 390 | } else { |
||
| 391 | $fsList['file'][$srcPath] = false; |
||
| 392 | } |
||
| 393 | |||
| 394 | $onFunctions = array(); |
||
| 395 | $onEvents = array(); |
||
| 396 | |||
| 397 | //イベント |
||
| 398 | $events = $paramList['events']['value']; |
||
| 399 | if (count($events) > 0) { |
||
| 400 | foreach ($events as $eventKey => $eventConst) { |
||
| 401 | $onEvents[$eventKey] = array(array('on' . $eventConst . ', NORMAL')); |
||
| 402 | $onFunctions[] = 'on' . $eventConst; |
||
| 403 | } |
||
| 404 | } |
||
| 405 | |||
| 406 | //フックポイント |
||
| 407 | $hookPoints = $paramList['hookPoints']['value']; |
||
| 408 | if (count($hookPoints)) { |
||
| 409 | foreach ($hookPoints as $hookKey => $hookConst) { |
||
| 410 | $onName = 'on' . join(array_map('ucfirst', explode('_', strtolower($hookConst)))); |
||
| 411 | $onEvents[$hookKey] = array(array($onName . ', NORMAL')); |
||
| 412 | $onFunctions[] = $onName; |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | if (count($onEvents)) { |
||
| 417 | $srcPath = $codePath . '/event.yml'; |
||
| 418 | file_put_contents($srcPath, str_replace('\'', '', Yaml::dump($onEvents))); |
||
| 419 | View Code Duplication | if (is_file($srcPath)) { |
|
| 420 | $fsList['file'][$srcPath] = true; |
||
| 421 | } else { |
||
| 422 | $fsList['file'][$srcPath] = false; |
||
| 423 | } |
||
| 424 | |||
| 425 | $pluginFileBefore = file_get_contents($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/EventHookpoint2.php'); |
||
| 426 | |||
| 427 | // Event |
||
| 428 | $from = '/\[code\]/'; |
||
| 429 | $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore); |
||
| 430 | $from = '/\[author\]/'; |
||
| 431 | $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter); |
||
| 432 | $from = '/\[year\]/'; |
||
| 433 | $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter); |
||
| 434 | |||
| 435 | $functions = ''; |
||
| 436 | foreach ($onFunctions as $functionName) { |
||
| 437 | $functions .= " public function " . $functionName . "(EventArgs \$event)\n {\n }\n\n"; |
||
| 438 | } |
||
| 439 | $from = '/\[hookpoint_function\]/'; |
||
| 440 | $pluginFileAfter = preg_replace($from, $functions, $pluginFileAfter); |
||
| 441 | $srcPath = $codePath . '/' . $code . 'Event.php'; |
||
| 442 | file_put_contents($srcPath, $pluginFileAfter); |
||
| 443 | View Code Duplication | if (is_file($srcPath)) { |
|
| 444 | $fsList['file'][$srcPath] = true; |
||
| 445 | } else { |
||
| 446 | $fsList['file'][$srcPath] = false; |
||
| 447 | } |
||
| 448 | } |
||
| 449 | |||
| 450 | // config.ymlを再作成 |
||
| 451 | $config = array(); |
||
| 452 | $config['name'] = $paramList['pluginName']['value']; |
||
| 453 | $config['code'] = $code; |
||
| 454 | $config['version'] = $paramList['version']['value']; |
||
| 455 | $config['event'] = $code . 'Event'; |
||
| 456 | $config['service'] = array($code . 'ServiceProvider'); |
||
| 457 | $srcPath = $codePath . '/config.yml'; |
||
| 458 | file_put_contents($srcPath, Yaml::dump($config)); |
||
| 459 | View Code Duplication | if (is_file($srcPath)) { |
|
| 460 | $fsList['file'][$srcPath] = true; |
||
| 461 | } else { |
||
| 462 | $fsList['file'][$srcPath] = false; |
||
| 463 | } |
||
| 464 | |||
| 465 | // LICENSE |
||
| 466 | $srcPath = $codePath . '/LICENSE'; |
||
| 467 | $file->copy($this->app['config']['root_dir'] . '/src/Eccube/Command/PluginCommand/Resource/LICENSE', $srcPath); |
||
| 468 | View Code Duplication | if (is_file($srcPath)) { |
|
| 469 | $fsList['file'][$srcPath] = true; |
||
| 470 | } else { |
||
| 471 | $fsList['file'][$srcPath] = false; |
||
| 472 | } |
||
| 473 | |||
| 474 | $dirFileNg = array(); |
||
| 475 | $dirFileOk = array(); |
||
| 476 | View Code Duplication | foreach ($fsList['dir'] as $path => $flag) { |
|
| 477 | if ($flag) { |
||
| 478 | $dirFileOk[] = $path; |
||
| 479 | } else { |
||
| 480 | $dirFileNg[] = $path; |
||
| 481 | } |
||
| 482 | } |
||
| 483 | View Code Duplication | foreach ($fsList['file'] as $path => $flag) { |
|
| 484 | if ($flag) { |
||
| 485 | $dirFileOk[] = $path; |
||
| 486 | } else { |
||
| 487 | $dirFileNg[] = $path; |
||
| 488 | } |
||
| 489 | } |
||
| 490 | $this->output->writeln(''); |
||
| 491 | $this->output->writeln('[+]File system'); |
||
| 492 | View Code Duplication | if (!empty($dirFileOk)) { |
|
| 493 | $this->output->writeln(''); |
||
| 494 | $this->output->writeln(' this files and folders were created.'); |
||
| 495 | foreach ($dirFileOk as $path) { |
||
| 496 | $this->output->writeln('<info> - ' . $path . '</info>'); |
||
| 497 | } |
||
| 498 | } |
||
| 499 | |||
| 500 | View Code Duplication | if (!empty($dirFileNg)) { |
|
| 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>'); |
||
| 505 | } |
||
| 506 | } |
||
| 507 | } |
||
| 508 | |||
| 557 |