ShopifyError::isCurl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
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
    /**
18
     * Messages for codes with garbage response bodies.
19
     *
20
     * @see https://help.shopify.com/en/api/getting-started/response-status-codes
21
     */
22
    const NO_DATA = [
23
        400 => 'Bad Request',
24
        401 => 'Unauthorized',
25
        403 => 'Forbidden',
26
        423 => 'Locked',
27
        406 => 'Not Acceptable',
28
        500 => 'Internal Server Error',
29
        501 => 'Not Implemented',
30
        503 => 'Service Unavailable',
31
        504 => 'Gateway Timeout'
32
    ];
33
34
    /**
35
     * @var array
36
     */
37
    protected $curlInfo = [];
38
39
    /**
40
     * @param int $code
41
     * @param string $message
42
     * @param array $curlInfo
43
     */
44
    public function __construct(int $code, string $message, array $curlInfo)
45
    {
46
        parent::__construct(self::NO_DATA[$code] ?? $message, $code);
47
        $this->curlInfo = $curlInfo;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getCurlInfo(): array
54
    {
55
        return $this->curlInfo;
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    final public function isCurl(): bool
62
    {
63
        return $this->code < 400;
64
    }
65
}