Completed
Push — 4.0 ( 8a9683...64d855 )
by Ryo
11:41 queued 04:40
created

PluginApiException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
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\Exception;
15
16
class PluginApiException extends \Exception
17
{
18
    private $curlInfo;
19
20
    /**
21
     * PluginApiException constructor.
22
     *
23
     * @param $curlInfo
24
     */
25
    public function __construct($curlInfo)
26
    {
27
        parent::__construct(self::getResponseErrorMessage($curlInfo), $curlInfo['http_code']);
28
        $this->curlInfo = $curlInfo;
29
    }
30
31
    private static function getResponseErrorMessage($info)
32
    {
33
        if (!empty($info)) {
34
            $messageId = 'admin.store.package.api.'.$info['http_code'].'.error';
35
            $message = trans($messageId);
36
            if ($message === $messageId) {
37
                $statusCode = $info['http_code'];
38
                $message = $info['message'];
39
                $message = $statusCode.' : '.$message;
40
            }
41
        } else {
42
            $message = trans('ownerstore.text.error.timeout');
43
        }
44
45
        return $message;
46
    }
47
}
48