DnsRecords::getFields()   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 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 *
5
 * Copyright (C) 2018  Ross Mitchell
6
 *
7
 * This file is part of RossMitchell/UpdateCloudFlare.
8
 *
9
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
10
 * it and/or modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace RossMitchell\UpdateCloudFlare\Requests;
24
25
use RossMitchell\UpdateCloudFlare\Data\SubDomainInfo;
26
use RossMitchell\UpdateCloudFlare\Interfaces\ConfigInterface;
27
use RossMitchell\UpdateCloudFlare\Interfaces\HeadersInterface;
28
use RossMitchell\UpdateCloudFlare\Interfaces\RequestInterface;
29
use Symfony\Component\Console\Exception\LogicException;
30
31
/**
32
 * Class DnsRecords
33
 * @package RossMitchell\UpdateCloudFlare\Data
34
 */
35
class DnsRecords implements RequestInterface
36
{
37
    /**
38
     * @var HeadersInterface
39
     */
40
    private $headers;
41
    /**
42
     * @var ConfigInterface
43
     */
44
    private $config;
45
    /**
46
     * @var SubDomainInfo
47
     */
48
    private $subDomainInfo;
49
50
    /**
51
     * DnsRecords constructor.
52
     *
53
     * @param ConfigInterface  $config
54
     * @param HeadersInterface $headers
55
     * @param SubDomainInfo    $subDomainInfo
56
     */
57 10
    public function __construct(ConfigInterface $config, HeadersInterface $headers, SubDomainInfo $subDomainInfo)
58
    {
59 10
        $this->config        = $config;
60 10
        $this->headers       = $headers;
61 10
        $this->subDomainInfo = $subDomainInfo;
62 10
    }
63
64
    /**
65
     * If headers need to be sent through then they can be returned with this method. If not return an empty array
66
     *
67
     * @return array
68
     */
69 1
    public function getHeaders(): array
70
    {
71 1
        return $this->headers->getHeadersArray();
72
    }
73
74
    /**
75
     * They type of request that is going to be made
76
     *
77
     * @return string
78
     */
79 1
    public function getRequestType(): string
80
    {
81 1
        return 'GET';
82
    }
83
84
    /**
85
     * If the request needs data to be sent though return it here. If not return an empty array
86
     *
87
     * @return array
88
     */
89 1
    public function getFields(): array
90
    {
91 1
        return [];
92
    }
93
94
    /**
95
     * Return the URL that the request should be made to
96
     *
97
     * @return string
98
     * @throws \RuntimeException
99
     * @throws LogicException
100
     */
101 1
    public function getUrl(): string
102
    {
103 1
        $baseUrl       = $this->config->getApiUrl();
104 1
        $subDomainInfo = $this->getSubDomainInfo();
105 1
        $zoneID        = $subDomainInfo->getZoneId();
106 1
        $type          = $subDomainInfo->getIpType();
107 1
        $subDomain     = $subDomainInfo->getSubDomain();
108 1
        $domain        = $this->config->getBaseUrl();
109
        $fullDomain    = "${subDomain}.${domain}";
110
111 1
        return "${baseUrl}zones/${zoneID}/dns_records?type=$type&name=$fullDomain";
112
    }
113
114
    /**
115
     * @return SubDomainInfo
116
     */
117
    public function getSubDomainInfo(): SubDomainInfo
118
    {
119 2
        return $this->subDomainInfo;
120
    }
121
}
122