Abokifx   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateApiKey() 0 7 3
A setApiToken() 0 4 1
A setResponseType() 0 3 1
A getApiToken() 0 3 1
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