Passed
Push — master ( c53e9c...76439b )
by Ross
02:52
created

GetDnsZones::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\Interfaces\ConfigInterface;
27
use RossMitchell\UpdateCloudFlare\Interfaces\CurlInterface;
28
use RossMitchell\UpdateCloudFlare\Interfaces\HeadersInterface;
29
use RossMitchell\UpdateCloudFlare\Interfaces\RequestInterface;
30
31
/**
32
 * This is used to get the zone information for the base domain
33
 *
34
 * @package RossMitchell\UpdateCloudFlare
35
 */
36
class GetDnsZones implements RequestInterface
37
{
38
    /**
39
     * @var ConfigInterface
40
     */
41
    private $config;
42
    /**
43
     * @var HeadersInterface
44
     */
45
    private $headers;
46
    /**
47
     * @var string
48
     */
49
    private $zoneId;
50
    /**
51
     * @var CurlInterface
52
     */
53
    private $curl;
54
55
    /**
56
     * GetDnsZones constructor.
57
     *
58
     * @param ConfigInterface  $config
59
     * @param HeadersInterface $headers
60
     * @param CurlInterface    $curl
61
     */
62
    public function __construct(ConfigInterface $config, HeadersInterface $headers, CurlInterface $curl)
63
    {
64
        $this->config  = $config;
65
        $this->headers = $headers;
66
        $this->curl    = $curl;
67
    }
68
69
    /**
70
     * @return string
71
     * @throws \Symfony\Component\Console\Exception\LogicException
72
     * @throws \RuntimeException
73
     * @throws CloudFlareException
74
     */
75
    public function getZoneInformation(): string
76
    {
77
        $result = \json_decode($this->curl->makeRequest($this));
78
79
        if ($result->success !== true) {
80
            $error = new CloudFlareException();
81
            $error->setDetails($result, self::class);
0 ignored issues
show
Unused Code introduced by
The call to RossMitchell\UpdateCloud...Exception::setDetails() has too many arguments starting with self::class. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
            $error->/** @scrutinizer ignore-call */ 
82
                    setDetails($result, self::class);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
82
            throw $error;
83
        }
84
85
        $this->zoneId = $result->result[0]->id;
86
87
        return $this->zoneId;
88
    }
89
90
    /**
91
     * If headers need to be sent through then they can be returned with this method. If not return an empty array
92
     *
93
     * @return array
94
     */
95
    public function getHeaders(): array
96
    {
97
        return $this->headers->getHeadersArray();
98
    }
99
100
    /**
101
     * They type of request that is going to be made
102
     *
103
     * @return string
104
     */
105
    public function getRequestType(): string
106
    {
107
        return 'GET';
108
    }
109
110
    /**
111
     * If the request needs data to be sent though return it here. If not return an empty array
112
     *
113
     * @return array
114
     */
115
    public function getFields(): array
116
    {
117
        return [];
118
    }
119
120
    /**
121
     * Return the URL that the request should be made to
122
     *
123
     * @return string
124
     */
125
    public function getUrl(): string
126
    {
127
        $baseUrl = $this->config->getApiUrl();
128
        $domain  = $this->config->getBaseUrl();
129
130
        return "${baseUrl}zones?name=${domain}";
131
    }
132
}
133