Abokifx::getApiToken()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Digikraaft\Abokifx;
4
5
use Digikraaft\Abokifx\Exceptions\InvalidArgumentException;
6
7
class Abokifx extends ApiResource
8
{
9
    const OBJECT_RESPONSE = 'obj';
10
    const ARRAY_RESPONSE = 'arr';
11
12
    /** @var string The abokiFX API key to be used for requests. */
13
    public static string $apiToken;
14
15
    /** @var string The base URL for the Abokifx API. */
16
    public static $apiBaseUrl = 'https://abokifx.com/api/v1';
17
18
    public static $responseType = self::ARRAY_RESPONSE;
19
20
    /**
21
     * @return string the API key used for requests
22
     */
23
    public static function getApiToken()
24
    {
25
        return self::$apiToken;
26
    }
27
28
    /**
29
     * Sets the API key to be used for requests.
30
     *
31
     * @param string $apiToken
32
     */
33
    public static function setApiToken($apiToken)
34
    {
35
        self::validateApiKey($apiToken);
36
        self::$apiToken = $apiToken;
37
    }
38
39
    /**
40
     * @param $apiKey
41
     * @return bool
42
     * @throws InvalidArgumentException
43
     */
44
    private static function validateApiKey($apiKey)
45
    {
46
        if ($apiKey == '' || ! is_string($apiKey)) {
47
            throw new InvalidArgumentException('Secret key must be a string and cannot be empty');
48
        }
49
50
        return true;
51
    }
52
53
    /**
54
     * @param string $responseType
55
     */
56
    public static function setResponseType(string $responseType)
57
    {
58
        Abokifx::$responseType = $responseType;
59
    }
60
}
61