Completed
Pull Request — 4.0 (#3997)
by chihiro
07:09 queued 01:03
created

ComposerRequireAlreadyInstalledPluginsCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A initialize() 0 4 1
B execute() 0 34 7
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 Doctrine\Common\Collections\Criteria;
17
use Eccube\Common\Constant;
18
use Eccube\Repository\PluginRepository;
19
use Eccube\Service\Composer\ComposerApiService;
20
use Eccube\Service\PluginApiService;
21
use Symfony\Component\Console\Command\Command;
22
use Symfony\Component\Console\Input\InputInterface;
23
use Symfony\Component\Console\Output\OutputInterface;
24
use Symfony\Component\Console\Question\ConfirmationQuestion;
25
use Symfony\Component\Console\Style\SymfonyStyle;
26
27
28
class ComposerRequireAlreadyInstalledPluginsCommand extends Command
29
{
30
    protected static $defaultName = 'eccube:composer:require-already-installed';
31
32
    /**
33
     * @var ComposerApiService
34
     */
35
    private $composerService;
36
37
    /**
38
     * @var PluginApiService
39
     */
40
    private $pluginApiService;
41
42
    /**
43
     * @var PluginRepository
44
     */
45
    private $pluginRepository;
46
47
    /**
48
     * @var SymfonyStyle
49
     */
50
    private $io;
51
52
    public function __construct(
53
        ComposerApiService $composerService,
54
        PluginRepository $pluginRepository,
55
        PluginApiService $pluginApiService
56
    ) {
57
        parent::__construct();
58
        $this->composerService = $composerService;
59
        $this->pluginApiService = $pluginApiService;
60
        $this->pluginRepository = $pluginRepository;
61
    }
62
63
    public function initialize(InputInterface $input, OutputInterface $output)
64
    {
65
        $this->io = new SymfonyStyle($input, $output);
66
    }
67
68
    protected function execute(InputInterface $input, OutputInterface $output)
69
    {
70
        $packageNames = [];
71
        $unSupportedPlugins = [];
72
73
        $criteria = Criteria::create()
74
            ->where(Criteria::expr()->neq('source', 0))
75
            ->orderBy(['code' => 'ASC']);
76
        $Plugins = $this->pluginRepository->matching($criteria);
77
78
        foreach ($Plugins as $Plugin) {
79
            $packageNames[] = 'ec-cube/'.$Plugin->getCode().':'.$Plugin->getVersion();
80
            $data = $this->pluginApiService->getPlugin($Plugin->getCode());
81
            if (isset($data['version_check']) && !$data['version_check']) {
82
                $unSupportedPlugins[] = $Plugin;
83
            }
84
        }
85
86
        foreach ($unSupportedPlugins as $Plugin) {
87
            $message = trans('command.composer_require_already_installed.not_supported_plugin', [
88
                '%name%' => $Plugin->getName(),
89
                '%plugin_version%' => $Plugin->getVersion(),
90
                '%eccube_version%' => Constant::VERSION
91
            ]);
92
            $question = new ConfirmationQuestion($message);
93
            if (!$this->io->askQuestion($question)) {
94
                return;
95
            }
96
        }
97
98
        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...
99
            $this->composerService->execRequire(implode(' ', $packageNames), $this->io);
100
        }
101
    }
102
}
103