Passed
Push — master ( 199ece...6bc7da )
by y
02:13
created

ShopifyError::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Helix\Shopify\Api;
4
5
use RuntimeException;
6
7
/**
8
 * A cURL or Shopify error.
9
 *
10
 * Errors with codes below 400 are cURL errors.
11
 *
12
 * The API class returns `null` for `404`; it's never thrown.
13
 */
14
class ShopifyError extends RuntimeException {
15
16
    /**
17
     * Messages for codes with garbage response bodies.
18
     *
19
     * @see https://help.shopify.com/en/api/getting-started/response-status-codes
20
     */
21
    const NO_DATA = [
22
        400 => 'Bad Request',
23
        401 => 'Unauthorized',
24
        403 => 'Forbidden',
25
        423 => 'Locked',
26
        406 => 'Not Acceptable',
27
        500 => 'Internal Server Error',
28
        501 => 'Not Implemented',
29
        503 => 'Service Unavailable',
30
        504 => 'Gateway Timeout'
31
    ];
32
33
    /**
34
     * @var array
35
     */
36
    protected $curlInfo = [];
37
38
    /**
39
     * @param int $code
40
     * @param string $message
41
     * @param array $curlInfo
42
     */
43
    public function __construct (int $code, string $message, array $curlInfo) {
44
        parent::__construct(self::NO_DATA[$code] ?? $message, $code);
45
        $this->curlInfo = $curlInfo;
46
    }
47
48
    /**
49
     * @return array
50
     */
51
    public function getCurlInfo (): array {
52
        return $this->curlInfo;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    final public function isCurl (): bool {
59
        return $this->code < 400;
60
    }
61
}