LoqateApi::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
4
namespace LaravelLoqate;
5
6
use LaravelLoqate\APIs\AbstractAPI;
7
use LaravelLoqate\APIs\CaptureInteractiveFind;
8
use LaravelLoqate\APIs\CaptureInteractiveRetrieve;
9
10
class LoqateApi
11
{
12
    protected string $key;
13
14
    /**
15
     * LoqateApi constructor.
16
     *
17
     * @param string $key
18
     */
19 2
    public function __construct(string $key)
20
    {
21 2
        $this->key = $key;
22
    }
23
24
    /**
25
     * Initialise api class
26
     *
27
     * @param string $abstract - Class name
28
     * @param string|null $key - Optional api key if you need override default key
29
     *
30
     * @return AbstractAPI
31
     */
32 2
    public function api(string $abstract, ?string $key = null): AbstractAPI
33
    {
34 2
        if (!is_subclass_of($abstract, AbstractAPI::class)) {
35 1
            throw new LoqateException('$abstract should be child of AbstractAPI');
36
        }
37
38 2
        return new $abstract($key ?? $this->key);
39
    }
40
41
    /**
42
     * @param string|null $key
43
     *
44
     * @return CaptureInteractiveFind
45
     */
46 2
    public function captureInteractiveFind(?string $key = null): CaptureInteractiveFind
47
    {
48 2
        return $this->api(CaptureInteractiveFind::class, $key);
49
    }
50
51
    /**
52
     * @param string|null $key
53
     *
54
     * @return CaptureInteractiveRetrieve
55
     */
56 1
    public function captureInteractiveRetrieve(?string $key = null): CaptureInteractiveRetrieve
57
    {
58 1
        return $this->api(CaptureInteractiveRetrieve::class, $key);
59
    }
60
}
61