Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

Eccube/Service/Composer/ComposerProcessService.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.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\Service\Composer;
15
16
use Doctrine\ORM\EntityManagerInterface;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\BaseInfo;
19
use Eccube\Exception\PluginException;
20
use Eccube\Repository\BaseInfoRepository;
21
22
/**
23
 * Class ComposerProcessService
24
 */
25
class ComposerProcessService implements ComposerServiceInterface
26
{
27
    /**
28
     * @var EccubeConfig config parameter
29
     */
30
    protected $eccubeConfig;
31
32
    /**
33
     * @var EntityManagerInterface
34
     */
35
    protected $entityManager;
36
37
    private $workingDir;
38
39
    /**
40
     * @var ComposerApiService
41
     */
42
    private $composerApiService;
43
    /**
44
     * @var BaseInfoRepository
45
     */
46
    private $baseInfoRepository;
47
48
    /**
49
     * ComposerProcessService constructor.
50
     *
51
     * @param EccubeConfig $eccubeConfig
52
     * @param EntityManagerInterface $entityManager
53
     * @param ComposerApiService $composerApiService
54
     */
55
    public function __construct(EccubeConfig $eccubeConfig, EntityManagerInterface $entityManager, ComposerApiService $composerApiService, BaseInfoRepository $baseInfoRepository)
56
    {
57
        $this->eccubeConfig = $eccubeConfig;
58
        $this->entityManager = $entityManager;
59
        $this->composerApiService = $composerApiService;
60
        $this->baseInfoRepository = $baseInfoRepository;
61
    }
62
63
    public function execRequire($packageName, $output = null)
64
    {
65
        return $this->runCommand([
66
            'eccube:composer:require',
67
            $packageName,
68
        ], $output);
69
    }
70
71
    public function execRemove($packageName, $output = null)
72
    {
73
        return $this->runCommand([
74
            'eccube:composer:remove',
75
            $packageName,
76
        ], $output);
77
    }
78
79
    /**
80
     * Run command
81
     *
82
     * @throws PluginException
83
     *
84
     * @param string $command
0 ignored issues
show
There is no parameter named $command. Did you maybe mean $commands?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
85
     */
86
    public function runCommand($commands, $output = null, $init = true)
87
    {
88
        if ($init) {
89
            $this->init();
90
        }
91
92
        $command = implode(' ', array_merge(['bin/console'], $commands));
93
        try {
94
            // Execute command
95
            $returnValue = -1;
96
            $output = [];
97
            exec($command, $output, $returnValue);
98
99
            $outputString = implode(PHP_EOL, $output);
100
            if ($returnValue) {
101
                throw new PluginException($outputString);
102
            }
103
            log_info(PHP_EOL.$outputString.PHP_EOL);
104
105
            return $outputString;
106
        } catch (\Exception $exception) {
107
            throw new PluginException($exception->getMessage());
108
        }
109
    }
110
111
    /**
112
     * Set init
113
     *
114
     * @throws PluginException
115
     */
116
    private function init($BaseInfo = null)
117
    {
118
//        /**
119
//         * Mysql lock in transaction
120
//         *
121
//         * @see https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html
122
//         *
123
//         * @var EntityManagerInterface
124
//         */
125
//        $em = $this->entityManager;
126
//        if ($em->getConnection()->isTransactionActive()) {
127
//            $em->getConnection()->commit();
128
//            $em->getConnection()->beginTransaction();
129
//        }
130
131
        $BaseInfo = $BaseInfo ?: $this->baseInfoRepository->get();
132
        $this->composerApiService->configureRepository($BaseInfo);
133
    }
134
135
    public function execConfig($key, $value = null)
136
    {
137
        return $this->composerApiService->execConfig($key, $value);
138
    }
139
140
    public function configureRepository(BaseInfo $BaseInfo)
141
    {
142
        return $this->composerApiService->configureRepository($BaseInfo);
143
    }
144
145
    public function foreachRequires($packageName, $version, $callback, $typeFilter = null, $level = 0)
146
    {
147
        return $this->composerApiService->foreachRequires($packageName, $version, $callback, $typeFilter, $level);
148
    }
149
}
150