AbstractApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A extractMeta() 0 8 2
A getMeta() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the DigitalOceanV2 library.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DigitalOceanV2\Api;
13
14
use DigitalOceanV2\Adapter\AdapterInterface;
15
use DigitalOceanV2\Entity\Meta;
16
17
/**
18
 * @author Antoine Corcy <[email protected]>
19
 * @author Graham Campbell <[email protected]>
20
 */
21
abstract class AbstractApi
22
{
23
    /**
24
     * @var string
25
     */
26
    const ENDPOINT = 'https://api.digitalocean.com/v2';
27
28
    /**
29
     * @var AdapterInterface
30
     */
31
    protected $adapter;
32
33
    /**
34
     * @var string
35
     */
36
    protected $endpoint;
37
38
    /**
39
     * @var Meta
40
     */
41
    protected $meta;
42
43
    /**
44
     * @param AdapterInterface $adapter
45
     * @param string|null      $endpoint
46
     */
47
    public function __construct(AdapterInterface $adapter, $endpoint = null)
48
    {
49
        $this->adapter = $adapter;
50
        $this->endpoint = $endpoint ?: static::ENDPOINT;
51
    }
52
53
    /**
54
     * @param \stdClass $data
55
     *
56
     * @return Meta|null
57
     */
58
    protected function extractMeta(\StdClass $data)
59
    {
60
        if (isset($data->meta)) {
61
            $this->meta = new Meta($data->meta);
62
        }
63
64
        return $this->meta;
65
    }
66
67
    /**
68
     * @return Meta|null
69
     */
70
    public function getMeta()
71
    {
72
        return $this->meta;
73
    }
74
}
75