Domain::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Cocotte\DigitalOcean;
4
5
use Darsyn\IP\IP;
6
use DigitalOceanV2\Api;
7
use DigitalOceanV2\Entity;
8
9
final class Domain
10
{
11
12
    /**
13
     * @var Api\Domain
14
     */
15
    private $domainApi;
16
17
    /**
18
     * @param Api\Domain $domainApi
19
     */
20
    public function __construct(Api\Domain $domainApi)
21
    {
22
        $this->domainApi = $domainApi;
23
    }
24
25
    public function create(Hostname $hostname, IP $ip): Entity\Domain
26
    {
27
        return $this->domainApi->create(
28
            $hostname->domainName(),
29
            $ip->getShortAddress()
30
        );
31
    }
32
33
    public function delete(Hostname $hostname): void
34
    {
35
        $this->domainApi->delete(
36
            $hostname->domainName()
37
        );
38
    }
39
40
    public function exists(Hostname $hostname): bool
41
    {
42
        $domains = $this->domainApi->getAll();
43
44
        foreach ($domains as $domain) {
45
            if ($domain->name === $hostname->domainName()) {
46
                return true;
47
            }
48
        }
49
50
        return false;
51
    }
52
}