Passed
Push — master ( 262356...2c0ae5 )
by y
01:43
created

AsanaError::is()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helix\Asana\Api;
4
5
use Helix\Asana\Api;
6
use RuntimeException;
7
8
/**
9
 * An {@link Api} error.
10
 *
11
 * Codes less than `400` are cURL errors.
12
 *
13
 * The {@link Api} returns `null` on `404`, it doesn't throw.
14
 *
15
 * @see https://developers.asana.com/docs/errors
16
 */
17
class AsanaError extends RuntimeException {
18
19
    /**
20
     * @var array
21
     */
22
    protected $curlInfo;
23
24
    public function __construct (int $code, string $message, array $curlInfo) {
25
        parent::__construct($message, $code);
26
        $this->curlInfo = $curlInfo;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function asResponse () {
33
        return json_decode($this->getMessage(), true, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR);
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getCurlInfo (): array {
40
        return $this->curlInfo;
41
    }
42
43
    /**
44
     * @param int $code
45
     * @return bool
46
     */
47
    final public function is (int $code): bool {
48
        return $this->code === $code;
49
    }
50
}