Flutterwave::setApiKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Digikraaft\Flutterwave;
4
5
use Digikraaft\Flutterwave\Exceptions\InvalidArgumentException;
6
7
class Flutterwave
8
{
9
    /** @var string The Flutterwave 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 Flutterwave API. */
16
    public static $apiBase = 'https://api.flutterwave.com/v3';
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