Completed
Push — master ( d82a91...4d3fdb )
by Ross
02:33
created

GetSubDomainInfo::getRequestType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
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\Model\Requests;
24
25
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException;
26
use RossMitchell\UpdateCloudFlare\Factories\Responses\DnsRecordsFactory;
27
use RossMitchell\UpdateCloudFlare\Interfaces\CurlInterface;
28
use RossMitchell\UpdateCloudFlare\Requests\DnsRecords;
29
use Symfony\Component\Console\Exception\LogicException;
30
31
/**
32
 * Class GetSubDomainInfo
33
 * @package RossMitchell\UpdateCloudFlare\Data
34
 */
35
class GetSubDomainInfo
36
{
37
    /**
38
     * @var string
39
     */
40
    private $subDomainId;
41
    /**
42
     * @var string
43
     */
44
    private $subDomainIpAddress;
45
    /**
46
     * @var CurlInterface
47
     */
48
    private $curl;
49
    /**
50
     * @var DnsRecordsFactory
51
     */
52
    private $dnsRecordsFactory;
53
54
    /**
55
     * GetSubDomainInfo constructor.
56
     *
57
     * @param CurlInterface     $curl
58
     * @param DnsRecordsFactory $dnsRecordsFactory
59
     */
60 5
    public function __construct(CurlInterface $curl, DnsRecordsFactory $dnsRecordsFactory)
61
    {
62 5
        $this->curl              = $curl;
63 5
        $this->dnsRecordsFactory = $dnsRecordsFactory;
64 5
    }
65
66
    /**
67
     * @return string
68
     * @throws LogicException
69
     */
70 2
    public function getSubDomainId(): string
71
    {
72 2
        if ($this->subDomainId === null) {
73 1
            throw new LogicException('You must collect the information before getting the sub domain ID');
74
        }
75
76 1
        return $this->subDomainId;
77
    }
78
79
    /**
80
     * @return string
81
     * @throws LogicException
82
     */
83 2
    public function getSubDomainIpAddress(): string
84
    {
85 2
        if ($this->subDomainIpAddress === null) {
86 1
            throw new LogicException('You must collect the information before getting the IP Address');
87
        }
88
89 1
        return $this->subDomainIpAddress;
90
    }
91
92
    /**
93
     * @param DnsRecords $request
94
     *
95
     * @throws CloudFlareException
96
     */
97 3
    public function collectionInformation(DnsRecords $request)
98
    {
99 3
        $rawResult                = \json_decode($this->curl->makeRequest($request));
100 3
        $result                   = $this->dnsRecordsFactory->create($rawResult);
101 2
        $details                  = $result->getResult()[0];
102 2
        $this->subDomainId        = $details->getId();
103 2
        $this->subDomainIpAddress = $details->getContent();
104 2
    }
105
}
106