Completed
Pull Request — 4.0 (#3997)
by chihiro
06:06
created

initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Command;
15
16
use Eccube\Common\Constant;
17
use Eccube\Repository\PluginRepository;
18
use Eccube\Service\Composer\ComposerApiService;
19
use Eccube\Service\PluginApiService;
20
use Symfony\Component\Console\Command\Command;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
use Symfony\Component\Console\Question\ConfirmationQuestion;
24
use Symfony\Component\Console\Style\SymfonyStyle;
25
26
27
class ComposerRequireAlreadyInstalledPluginsCommand extends Command
28
{
29
    protected static $defaultName = 'eccube:composer:require-already-installed';
30
31
    /**
32
     * @var ComposerApiService
33
     */
34
    private $composerService;
35
36
    /**
37
     * @var PluginApiService
38
     */
39
    private $pluginApiService;
40
41
    /**
42
     * @var PluginRepository
43
     */
44
    private $pluginRepository;
45
46
    /**
47
     * @var SymfonyStyle
48
     */
49
    private $io;
50
51
    public function __construct(
52
        ComposerApiService $composerService,
53
        PluginRepository $pluginRepository,
54
        PluginApiService $pluginApiService
55
    ) {
56
        parent::__construct();
57
        $this->composerService = $composerService;
58
        $this->pluginApiService = $pluginApiService;
59
        $this->pluginRepository = $pluginRepository;
60
    }
61
62
    public function initialize(InputInterface $input, OutputInterface $output)
63
    {
64
        $this->io = new SymfonyStyle($input, $output);
65
    }
66
67
    protected function execute(InputInterface $input, OutputInterface $output)
68
    {
69
        $packageNames = [];
70
        $unSupportedPlugins = [];
71
72
        $Plugins = $this->pluginRepository->findAll();
73
        foreach ($Plugins as $Plugin) {
74
            $packageNames[] = 'ec-cube/'.$Plugin->getCode().':'.$Plugin->getVersion();
75
            $data = $this->pluginApiService->getPlugin($Plugin->getCode());
76
            if (isset($data['version_check']) && !$data['version_check']) {
77
                $unSupportedPlugins[] = $Plugin;
78
            }
79
        }
80
81
        foreach ($unSupportedPlugins as $Plugin) {
82
            $message = trans('command.composer_require_already_installed.not_supported_plugin', [
83
                '%name%' => $Plugin->getName(),
84
                '%plugin_version%' => $Plugin->getVersion(),
85
                '%eccube_version%' => Constant::VERSION
86
            ]);
87
            $question = new ConfirmationQuestion($message);
88
            if (!$this->io->askQuestion($question)) {
89
                return;
90
            }
91
        }
92
93
        if ($packageNames) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $packageNames of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
94
            $this->composerService->execRequire(implode(' ', $packageNames), $this->io);
95
        }
96
    }
97
}
98