Paystack::validateApiKey()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
c 1
b 0
f 0
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Digikraaft\Paystack;
4
5
use Digikraaft\Paystack\Exceptions\InvalidArgumentException;
6
7
class Paystack
8
{
9
    /** @var string The Paystack API key to be used for requests. */
10
    public static string $apiKey;
11
12
    /** @var string The instance API key, settable once per new instance */
13
    private $instanceApiKey;
0 ignored issues
show
introduced by
The private property $instanceApiKey is not used, and could be removed.
Loading history...
14
15
    /** @var string The base URL for the Paystack API. */
16
    public static $apiBase = 'https://api.paystack.co';
17
18
    /**
19
     * @return string the API key used for requests
20
     */
21
    public static function getApiKey(): string
22
    {
23
        return self::$apiKey;
24
    }
25
26
    /**
27
     * Sets the API key to be used for requests.
28
     *
29
     * @param string $apiKey
30
     */
31
    public static function setApiKey($apiKey): void
32
    {
33
        self::validateApiKey($apiKey);
34
        self::$apiKey = $apiKey;
35
    }
36
37
    private static function validateApiKey($apiKey): bool
38
    {
39
        if ($apiKey == '' || ! is_string($apiKey)) {
40
            throw new InvalidArgumentException('Api key must be a string and cannot be empty');
41
        }
42
43
        return true;
44
    }
45
}
46