Passed
Push — master ( 7394e3...ac5429 )
by Ross
02:44
created

GetIpAddress::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Interfaces\CurlInterface;
26
use RossMitchell\UpdateCloudFlare\Interfaces\RequestInterface;
27
28
/**
29
 * Class GetIpAddress
30
 * @package RossMitchell\UpdateCloudFlare\Model\Requests
31
 */
32
class GetIpAddress implements RequestInterface
33
{
34
    /**
35
     * @var CurlInterface
36
     */
37
    private $curl;
38
39
    /**
40
     * GetIpAddress constructor.
41
     *
42
     * @param CurlInterface $curl
43
     */
44
    public function __construct(CurlInterface $curl)
45
    {
46
        $this->curl = $curl;
47
    }
48
49
    /**
50
     * This will make the request and return the current external IP address.
51
     *
52
     * @return string
53
     * @throws \Symfony\Component\Console\Exception\LogicException
54
     * @throws \RuntimeException
55
     */
56
    public function getIpAddress(): string
57
    {
58
        $result = $this->curl->makeRequest($this);
59
60
        return trim($result);
61
    }
62
63
    /**
64
     * They type of request that is going to be made
65
     *
66
     * @return string
67
     */
68
    public function getRequestType(): string
69
    {
70
        return 'GET';
71
    }
72
73
    /**
74
     * If the request needs data to be sent though return it here. If not return an empty array
75
     *
76
     * @return array
77
     */
78
    public function getFields(): array
79
    {
80
        return [];
81
    }
82
83
    /**
84
     * Return the URL that the request should be made to
85
     *
86
     * @return string
87
     */
88
    public function getUrl(): string
89
    {
90
        return 'http://ifconfig.co';
91
    }
92
93
94
    /**
95
     * If headers need to be sent through then they can be returned with this method. If not return an empty array
96
     *
97
     * @return array
98
     */
99
    public function getHeaders(): array
100
    {
101
        return [];
102
    }
103
}
104