Completed
Push — dev/store-tests ( b538ec...90db53 )
by Kiyotaka
05:40
created

ComposerProcessService::execConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
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\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;
0 ignored issues
show
Unused Code introduced by
The property $workingDir is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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
Documentation introduced by
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)
0 ignored issues
show
Unused Code introduced by
The parameter $output is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $returnValue of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
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
        return $this->composerApiService->execConfig($key, $value);
137
    }
138
139
    public function configureRepository(BaseInfo $BaseInfo)
140
    {
141
        return $this->composerApiService->configureRepository($BaseInfo);
142
    }
143
144
    public function foreachRequires($packageName, $version, $callback, $typeFilter = null, $level = 0)
145
    {
146
        return $this->composerApiService->foreachRequires($packageName, $version, $callback, $typeFilter, $level);
147
    }
148
}
149