Request::setUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * WooCommerce REST API HTTP Client Request
4
 *
5
 * @category HttpClient
6
 * @package  Automattic/WooCommerce
7
 */
8
9
namespace Automattic\WooCommerce\HttpClient;
10
11
/**
12
 * REST API HTTP Client Request class.
13
 *
14
 * @package Automattic/WooCommerce
15
 */
16
class Request
17
{
18
19
    /**
20
     * Request url.
21
     *
22
     * @var string
23
     */
24
    private $url;
25
26
    /**
27
     * Request method.
28
     *
29
     * @var string
30
     */
31
    private $method;
32
33
    /**
34
     * Request paramenters.
35
     *
36
     * @var array
37
     */
38
    private $parameters;
39
40
    /**
41
     * Request headers.
42
     *
43
     * @var array
44
     */
45
    private $headers;
46
47
    /**
48
     * Request body.
49
     *
50
     * @var string
51
     */
52
    private $body;
53
54
    /**
55
     * Initialize request.
56
     *
57
     * @param string $url        Request url.
58
     * @param string $method     Request method.
59
     * @param array  $parameters Request paramenters.
60
     * @param array  $headers    Request headers.
61
     * @param string $body       Request body.
62
     */
63
    public function __construct($url = '', $method = 'POST', $parameters = [], $headers = [], $body = '')
64
    {
65
        $this->url        = $url;
66
        $this->method     = $method;
67
        $this->parameters = $parameters;
68
        $this->headers    = $headers;
69
        $this->body       = $body;
70
    }
71
72
    /**
73
     * Set url.
74
     *
75
     * @param string $url Request url.
76
     */
77
    public function setUrl($url)
78
    {
79
        $this->url = $url;
80
    }
81
82
    /**
83
     * Set method.
84
     *
85
     * @param string $method Request method.
86
     */
87
    public function setMethod($method)
88
    {
89
        $this->method = $method;
90
    }
91
92
    /**
93
     * Set parameters.
94
     *
95
     * @param array $parameters Request paramenters.
96
     */
97
    public function setParameters($parameters)
98
    {
99
        $this->parameters = $parameters;
100
    }
101
102
    /**
103
     * Set headers.
104
     *
105
     * @param array $headers Request headers.
106
     */
107
    public function setHeaders($headers)
108
    {
109
        $this->headers = $headers;
110
    }
111
112
    /**
113
     * Set body.
114
     *
115
     * @param string $body Request body.
116
     */
117
    public function setBody($body)
118
    {
119
        $this->body = $body;
120
    }
121
122
    /**
123
     * Get url.
124
     *
125
     * @return string
126
     */
127
    public function getUrl()
128
    {
129
        return $this->url;
130
    }
131
132
    /**
133
     * Get method.
134
     *
135
     * @return string
136
     */
137
    public function getMethod()
138
    {
139
        return $this->method;
140
    }
141
142
    /**
143
     * Get parameters.
144
     *
145
     * @return array
146
     */
147
    public function getParameters()
148
    {
149
        return $this->parameters;
150
    }
151
152
    /**
153
     * Get headers.
154
     *
155
     * @return array
156
     */
157
    public function getHeaders()
158
    {
159
        return $this->headers;
160
    }
161
162
    /**
163
     * Get raw headers.
164
     *
165
     * @return array
166
     */
167
    public function getRawHeaders()
168
    {
169
        $headers = [];
170
171
        foreach ($this->headers as $key => $value) {
172
            $headers[] = $key . ': ' . $value;
173
        }
174
175
        return $headers;
176
    }
177
178
    /**
179
     * Get body.
180
     *
181
     * @return string
182
     */
183
    public function getBody()
184
    {
185
        return $this->body;
186
    }
187
}
188