Domain   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 12 1
A getByName() 0 8 1
A create() 0 10 1
A delete() 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\Entity\Domain as DomainEntity;
15
use DigitalOceanV2\Exception\HttpException;
16
17
/**
18
 * @author Yassir Hannoun <[email protected]>
19
 * @author Graham Campbell <[email protected]>
20
 */
21
class Domain extends AbstractApi
22
{
23
    /**
24
     * @param int $per_page
25
     * @param int $page
26
     *
27
     * @return DomainEntity[]
28
     */
29
    public function getAll($per_page = 200, $page = 1)
30
    {
31
        $domains = $this->adapter->get(sprintf('%s/domains?per_page=%d&page=%d', $this->endpoint, $per_page, $page));
32
33
        $domains = json_decode($domains);
34
35
        $this->extractMeta($domains);
36
37
        return array_map(function ($domain) {
38
            return new DomainEntity($domain);
39
        }, $domains->domains);
40
    }
41
42
    /**
43
     * @param string $domainName
44
     *
45
     * @throws HttpException
46
     *
47
     * @return DomainEntity
48
     */
49
    public function getByName($domainName)
50
    {
51
        $domain = $this->adapter->get(sprintf('%s/domains/%s', $this->endpoint, $domainName));
52
53
        $domain = json_decode($domain);
54
55
        return new DomainEntity($domain->domain);
56
    }
57
58
    /**
59
     * @param string $name
60
     * @param string $ipAddress
61
     *
62
     * @throws HttpException
63
     *
64
     * @return DomainEntity
65
     */
66
    public function create($name, $ipAddress)
67
    {
68
        $content = ['name' => $name, 'ip_address' => $ipAddress];
69
70
        $domain = $this->adapter->post(sprintf('%s/domains', $this->endpoint), $content);
71
72
        $domain = json_decode($domain);
73
74
        return new DomainEntity($domain->domain);
75
    }
76
77
    /**
78
     * @param string $domain
79
     *
80
     * @throws HttpException
81
     */
82
    public function delete($domain)
83
    {
84
        $this->adapter->delete(sprintf('%s/domains/%s', $this->endpoint, $domain));
85
    }
86
}
87