LoqateApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A captureInteractiveFind() 0 3 1
A captureInteractiveRetrieve() 0 3 1
A api() 0 7 2
A __construct() 0 3 1
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