Failed Conditions
Pull Request — experimental/3.1 (#2723)
by
unknown
79:43
created

OwnerStoreController::apiInstall()   D

Complexity

Conditions 8
Paths 246

Size

Total Lines 95
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 8
eloc 67
c 5
b 0
f 1
nc 246
nop 5
dl 0
loc 95
ccs 0
cts 16
cp 0
crap 72
rs 4.1498

How to fix   Long Method   

Long Method

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:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
namespace Eccube\Controller\Admin\Store;
24
25
use Doctrine\ORM\EntityManager;
26
use Eccube\Annotation\Inject;
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Controller\AbstractController;
30
use Eccube\Entity\Plugin;
31
use Eccube\Repository\PluginRepository;
32
use Eccube\Service\Composer\ComposerServiceInterface;
33
use Eccube\Service\PluginService;
34
use Eccube\Service\SystemService;
35
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
36
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
37
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
38
use Symfony\Component\HttpFoundation\RedirectResponse;
39
use Symfony\Component\HttpFoundation\Request;
40
use Symfony\Component\HttpFoundation\Response;
41
use Symfony\Component\HttpFoundation\Session\Session;
42
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
43
44
/**
45
 * @Route("/{_admin}/store/plugin/api", service=OwnerStoreController::class)
46
 */
47
class OwnerStoreController extends AbstractController
48
{
49
    /**
50
     * @Inject("config")
51
     * @var array
52
     */
53
    protected $appConfig;
54
55
    /**
56
     * @Inject(PluginRepository::class)
57
     * @var PluginRepository
58
     */
59
    protected $pluginRepository;
60
61
    /**
62
     * @Inject(PluginService::class)
63
     * @var PluginService
64
     */
65
    protected $pluginService;
66
67
    /**
68
     * @Inject("eccube.service.composer")
69
     * @var ComposerServiceInterface
70
     */
71
    protected $composerService;
72
73
    /**
74
     * @var EntityManager
75
     * @Inject("orm.em")
76
     */
77
    protected $em;
78
79
    /**
80
     * @Inject(SystemService::class)
81
     * @var SystemService
82
     */
83
    protected $systemService;
84
85
    private static $vendorName = 'ec-cube';
86
87
    /**
88
     * Owner's Store Plugin Installation Screen - Search function
89
     *
90
     * @Route("/search", name="admin_store_plugin_owners_search")
91
     * @Template("Store/plugin_search.twig")
92
     * @param Application $app
93
     * @param Request     $request
94
     * @return array
95
     */
96
    public function search(Application $app, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
97
    {
98
        // Acquire downloadable plug-in information from owners store
99
        $items = array();
100
        $promotionItems = array();
101
        $message = '';
102
        // Owner's store communication
103
        $url = $this->appConfig['package_repo_url'].'/search/packages.json';
104
        list($json, $info) = $this->getRequestApi($url);
105
        if ($json === false) {
106
            $message = $this->getResponseErrorMessage($info);
107
        } else {
108
            $data = json_decode($json, true);
109
            if (isset($data['success']) && $data['success']) {
110
                // Check plugin installed
111
                $pluginInstalled = $this->pluginRepository->findAll();
112
                // Update_status 1 : not install/purchased 、2 : Installed、 3 : Update、4 : paid purchase
113
                foreach ($data['item'] as $item) {
114
                    // Not install/purchased
115
                    $item['update_status'] = 1;
116
                    /** @var Plugin $plugin */
117
                    foreach ($pluginInstalled as $plugin) {
118
                        if ($plugin->getSource() == $item['product_id']) {
119
                            // Installed
120
                            $item['update_status'] = 2;
121
                            if ($this->pluginService->isUpdate($plugin->getVersion(), $item['version'])) {
122
                                // Need update
123
                                $item['update_status'] = 3;
124
                            }
125
                        }
126
                    }
127
                    $items[] = $item;
128
                }
129
130
                // EC-CUBE version check
131
                foreach ($items as &$item) {
132
                    // Not applicable version
133
                    $item['version_check'] = 0;
134
                    if (in_array(Constant::VERSION, $item['eccube_version'])) {
135
                        // Match version
136
                        $item['version_check'] = 1;
137
                    }
138
                    if ($item['price'] != '0' && $item['purchased'] == '0') {
139
                        // Not purchased with paid items
140
                        $item['update_status'] = 4;
141
                    }
142
                    // Add plugin dependency
143
                    $item['depend'] = $this->pluginService->getRequirePluginName($items, $item);
144
                }
145
                unset($item);
146
147
                // Promotion item
148
                $i = 0;
149
                foreach ($items as $item) {
150
                    if ($item['promotion'] == 1) {
151
                        $promotionItems[] = $item;
152
                        unset($items[$i]);
153
                    }
154
                    $i++;
155
                }
156
            } else {
157
                $message = $app->trans('admin.plugin.authentication.fail');
158
            }
159
        }
160
161
        return [
162
            'items' => $items,
163
            'promotionItems' => $promotionItems,
164
            'message' => $message,
165
        ];
166
    }
167
168
    /**
169
     * Do confirm page
170
     *
171
     * @Route("/install/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_install_confirm")
172
     * @Template("Store/plugin_confirm.twig")
173
     * @param Application $app
174
     * @param Request     $request
175
     * @param string      $id
176
     * @return array
177
     */
178
    public function doConfirm(Application $app, Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $app 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...
179
    {
180
        // Owner's store communication
181
        $url = $this->appConfig['package_repo_url'].'/search/packages.json';
182
        list($json, $info) = $this->getRequestApi($url);
0 ignored issues
show
Unused Code introduced by
The assignment to $info is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
183
        $data = json_decode($json, true);
184
        $items = $data['item'];
185
186
        // Find plugin in api
187
        $index = array_search($id, array_column($items, 'product_id'));
188
        if ($index === false) {
189
            throw new NotFoundHttpException();
190
        }
191
192
        $pluginCode = $items[$index]['product_code'];
193
194
        $plugin = $this->pluginService->buildInfo($items, $pluginCode);
195
196
        // Prevent infinity loop: A -> B -> A.
197
        $dependents[] = $plugin;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dependents was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dependents = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
198
        $dependents = $this->pluginService->getDependency($items, $plugin, $dependents);
0 ignored issues
show
Bug introduced by
It seems like $plugin defined by $this->pluginService->bu...fo($items, $pluginCode) on line 194 can also be of type null; however, Eccube\Service\PluginService::getDependency() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
199
        // Unset first param
200
        unset($dependents[0]);
201
202
        return [
203
            'item' => $plugin,
204
            'dependents' => $dependents,
205
            'is_update' => $request->get('is_update', false),
206
        ];
207
    }
208
209
    /**
210
     * Api Install plugin by composer connect with package repo
211
     *
212
     * @Route("/install/{pluginCode}/{eccubeVersion}/{version}" , name="admin_store_plugin_api_install")
213
     *
214
     * @param Application $app
215
     * @param Request     $request
216
     * @param string      $pluginCode
217
     * @param string      $eccubeVersion
218
     * @param string      $version
219
     * @return RedirectResponse
220
     */
221
    public function apiInstall(Application $app, Request $request, $pluginCode, $eccubeVersion, $version)
222
    {
223
        // Check plugin code
224
        $url = $this->appConfig['package_repo_url'].'/search/packages.json'.'?eccube_version='.$eccubeVersion.'&plugin_code='.$pluginCode.'&version='.$version;
225
        list($json, $info) = $this->getRequestApi($url);
0 ignored issues
show
Unused Code introduced by
The assignment to $info is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
226
        $existFlg = false;
227
        $data = json_decode($json, true);
228
        if (isset($data['item']) && !empty($data['item'])) {
229
            $existFlg = $this->pluginService->checkPluginExist($data['item'], $pluginCode);
230
        }
231
        if ($existFlg === false) {
232
            log_info(sprintf('%s plugin not found!', $pluginCode));
233
            $app->addError('admin.plugin.not.found', 'admin');
234
235
            return $app->redirect($app->url('admin_store_plugin_owners_search'));
236
        }
237
238
        $items = $data['item'];
239
        $plugin = $this->pluginService->buildInfo($items, $pluginCode);
240
        $dependents[] = $plugin;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dependents was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dependents = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
241
        $dependents = $this->pluginService->getDependency($items, $plugin, $dependents);
0 ignored issues
show
Bug introduced by
It seems like $plugin defined by $this->pluginService->bu...fo($items, $pluginCode) on line 239 can also be of type null; however, Eccube\Service\PluginService::getDependency() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
242
        // Unset first param
243
        unset($dependents[0]);
244
245
        $dependentModifier = [];
246
        $packageNames = '';
247
        if (!empty($dependents)) {
248
            foreach ($dependents as $key => $item) {
249
                $pluginItem = [
250
                    "product_code" => $item['product_code'],
251
                    "version" => $item['version'],
252
                ];
253
                $dependentModifier[] = $pluginItem;
254
                // Re-format plugin code
255
                $dependents[$key]['product_code'] = self::$vendorName.'/'.$item['product_code'];
256
            }
257
            $packages = array_column($dependents, 'version', 'product_code');
258
            $packageNames = $this->pluginService->parseToComposerCommand($packages);
259
        }
260
        $packageNames .= ' '.self::$vendorName.'/'.$pluginCode.':'.$version;
261
262
        // Upgrade plugin backup
263
        $isUpgrade = $request->get('is_upgrade', false);
0 ignored issues
show
Unused Code introduced by
$isUpgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
264
        $updateData = $dependentModifier;
265
        $updateData[] = [
266
            'product_code' => $pluginCode,
267
            'version' => $version,
268
        ];
269
        $this->pluginService->doBackup($updateData);
270
271
        $reportData = array(
272
            'code' => $pluginCode,
273
            'version' => $version,
274
            'core_version' => $eccubeVersion,
275
            'php_version' => phpversion(),
276
            'db_version' => $this->systemService->getDbversion(),
277
            'os' => php_uname('s').' '.php_uname('r').' '.php_uname('v'),
278
            'host' => $request->getHost(),
279
            'web_server' => $request->server->get("SERVER_SOFTWARE"),
280
            'composer_version' => $this->composerService->composerVersion(),
281
            'composer_execute_mode' => $this->composerService->getMode(),
282
            'dependents' => json_encode($dependentModifier),
283
        );
284
        try {
285
            $this->composerService->execRequire($packageNames);
286
            // Do report to package repo
287
            $url = $this->appConfig['package_repo_url'].'/report';
288
            $this->postRequestApi($url, $reportData);
289
            $app->addSuccess('admin.plugin.install.complete', 'admin');
290
291
            return $app->redirect($app->url('admin_store_plugin'));
292
        } catch (\Exception $exception) {
293
            log_error($exception->getMessage());
294
            // Do rollback when error
295
            $this->pluginService->doRollback($updateData);
296
        } finally {
297
            // Remove temp files
298
            $pluginTempRealDir = $this->appConfig['plugin_temp_realdir'];
299
            $dirs = [
300
                $pluginTempRealDir.'/composer.json',
301
                $pluginTempRealDir.'/composer.lock',
302
            ];
303
            foreach ($updateData as $value) {
304
                $dirs[] = $pluginTempRealDir.'/'.$value['product_code'];
305
            }
306
            $this->pluginService->deleteDirs($dirs);
307
        }
308
309
        // Do report to package repo
310
        $url = $this->appConfig['package_repo_url'].'/report/fail';
311
        $this->postRequestApi($url, $reportData);
312
        $app->addError('admin.plugin.install.fail', 'admin');
313
314
        return $app->redirect($app->url('admin_store_plugin_owners_search'));
315
    }
316
317
318
    /**
319
     * Do confirm page
320
     *
321
     * @Route("/delete/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_delete_confirm")
322
     * @Template("Store/plugin_confirm_uninstall.twig")
323
     * @param Application $app
324
     * @param Plugin      $Plugin
325
     * @return array|RedirectResponse
326
     */
327
    public function deleteConfirm(Application $app, Plugin $Plugin)
328
    {
329
        // Owner's store communication
330
        $url = $this->appConfig['package_repo_url'].'/search/packages.json';
331
        list($json, $info) = $this->getRequestApi($url);
0 ignored issues
show
Unused Code introduced by
The assignment to $info is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
332
        $data = json_decode($json, true);
333
        $items = $data['item'];
334
335
        // The plugin depends on it
336
        $pluginCode = $Plugin->getCode();
337
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
338
339
        if (!empty($otherDepend)) {
340
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
341
            $dependName = $otherDepend[0];
342
            if ($DependPlugin) {
343
                $dependName = $DependPlugin->getName();
344
            }
345
            $message = $app->trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
346
            $app->addError($message, 'admin');
347
348
            return $app->redirect($app->url('admin_store_plugin'));
349
        }
350
351
        // Check plugin in api
352
        $pluginSource = $Plugin->getSource();
353
        $index = array_search($pluginSource, array_column($items, 'product_id'));
354
        if ($index === false) {
355
            throw new NotFoundHttpException();
356
        }
357
358
        // Build info
359
        $pluginCode = $Plugin->getCode();
360
        $plugin = $this->pluginService->buildInfo($items, $pluginCode);
361
        $plugin['id'] = $Plugin->getId();
362
363
        return [
364
            'item' => $plugin,
365
        ];
366
    }
367
368
    /**
369
     * New ways to remove plugin: using composer command
370
     *
371
     * @Method("DELETE")
372
     * @Route("/delete/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_api_uninstall")
373
     * @param Application $app
374
     * @param Plugin      $Plugin
375
     * @return RedirectResponse
376
     */
377
    public function apiUninstall(Application $app, Plugin $Plugin)
378
    {
379
        $this->isTokenValid($app);
380
381
        if ($Plugin->isEnabled()) {
382
            $app->addError('admin.plugin.uninstall.error.not_disable', 'admin');
383
384
            return $app->redirect($app->url('admin_store_plugin'));
385
        }
386
387
        $pluginCode = $Plugin->getCode();
388
        $packageName = self::$vendorName.'/'.$pluginCode;
389
        try {
390
            $this->composerService->execRemove($packageName);
391
            $app->addSuccess('admin.plugin.uninstall.complete', 'admin');
392
        } catch (\Exception $exception) {
393
            log_info($exception);
394
            $app->addError('admin.plugin.uninstall.error', 'admin');
395
        }
396
397
        return $app->redirect($app->url('admin_store_plugin'));
398
    }
399
400
    /**
401
     * オーナーズブラグインインストール、アップデート
402
     *
403
     * @Method("PUT")
404
     * @Route("/upgrade/{pluginCode}/{version}", name="admin_store_plugin_api_upgrade")
405
     *
406
     * @param Application $app
407
     * @param string      $pluginCode
408
     * @param string      $version
409
     * @return RedirectResponse
410
     */
411
    public function apiUpgrade(Application $app, $pluginCode, $version)
412
    {
413
        $this->isTokenValid($app);
414
        // Run install plugin
415
        $app->forward($app->url('admin_store_plugin_api_install', ['pluginCode' => $pluginCode, 'eccubeVersion' => Constant::VERSION, 'version' => $version, 'is_upgrade' => true]));
416
417
        /** @var Session $session */
418
        $session = $app['session'];
419
        if ($session->getFlashBag()->has('eccube.admin.error')) {
420
            $session->getFlashBag()->clear();
421
            $app->addError('admin.plugin.update.error', 'admin');
422
423
            return $app->redirect($app->url('admin_store_plugin'));
424
        }
425
        $session->getFlashBag()->clear();
426
        $app->addSuccess('admin.plugin.update.complete', 'admin');
427
428
        return $app->redirect($app->url('admin_store_plugin'));
429
    }
430
431
    /**
432
     * Do confirm update page
433
     *
434
     * @Route("/upgrade/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_update_confirm")
435
     * @Template("Store/plugin_confirm.twig")
436
     * @param Application $app
437
     * @param Plugin      $plugin
438
     * @return Response
439
     */
440
    public function doUpgradeConfirm(Application $app, Plugin $plugin)
441
    {
442
        $source = $plugin->getSource();
443
        $url = $app->url('admin_store_plugin_install_confirm', ['id' => $source, 'is_update' => true]);
444
445
        return $app->forward($url);
446
    }
447
448
    /**
449
     * API request processing
450
     *
451
     * @param string  $url
452
     * @return array
453
     */
454
    private function getRequestApi($url)
455
    {
456
        $curl = curl_init($url);
457
458
        // Option array
459
        $options = array(
460
            // HEADER
461
            CURLOPT_HTTPGET => true,
462
            CURLOPT_SSL_VERIFYPEER => false,
463
            CURLOPT_RETURNTRANSFER => true,
464
            CURLOPT_FAILONERROR => true,
465
            CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(),
466
        );
467
468
        // Set option value
469
        curl_setopt_array($curl, $options);
470
        $result = curl_exec($curl);
471
        $info = curl_getinfo($curl);
472
        $message = curl_error($curl);
473
        $info['message'] = $message;
474
        curl_close($curl);
475
476
        log_info('http get_info', $info);
477
478
        return array($result, $info);
479
    }
480
481
    /**
482
     * API post request processing
483
     *
484
     * @param string  $url
485
     * @param array $data
486
     * @return array
487
     */
488
    private function postRequestApi($url, $data)
489
    {
490
        $curl = curl_init($url);
491
        curl_setopt($curl, CURLOPT_URL, $url);
492
        curl_setopt($curl, CURLOPT_POST, 1);
493
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
494
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
495
        $result = curl_exec($curl);
496
        $info = curl_getinfo($curl);
497
        $message = curl_error($curl);
498
        $info['message'] = $message;
499
        curl_close($curl);
500
        log_info('http post_info', $info);
501
502
        return array($result, $info);
503
    }
504
505
    /**
506
     * Get message
507
     *
508
     * @param $info
509
     * @return string
510
     */
511 View Code Duplication
    private function getResponseErrorMessage($info)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
512
    {
513
        if (!empty($info)) {
514
            $statusCode = $info['http_code'];
515
            $message = $info['message'];
516
517
            $message = $statusCode.' : '.$message;
518
        } else {
519
            $message = "タイムアウトエラーまたはURLの指定に誤りがあります。";
520
        }
521
522
        return $message;
523
    }
524
}
525