Passed
Pull Request — master (#31)
by Anatoly
39:30
created
src/Request.php 1 patch
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -36,301 +36,301 @@
 block discarded – undo
36 36
 class Request extends Message implements RequestInterface, RequestMethodInterface
37 37
 {
38 38
 
39
-    /**
40
-     * Regular Expression for a request target validation
41
-     *
42
-     * @link https://tools.ietf.org/html/rfc7230#section-5.3
43
-     *
44
-     * @var string
45
-     */
46
-    public const RFC7230_VALID_REQUEST_TARGET = '/^[\x21-\x7E\x80-\xFF]+$/';
47
-
48
-    /**
49
-     * Default request method
50
-     *
51
-     * @var string
52
-     */
53
-    public const DEFAULT_METHOD = self::METHOD_GET;
54
-
55
-    /**
56
-     * Default request URI
57
-     *
58
-     * @var string
59
-     */
60
-    public const DEFAULT_URI = '/';
61
-
62
-    /**
63
-     * The request method (aka verb)
64
-     *
65
-     * @var string
66
-     */
67
-    private string $method = self::DEFAULT_METHOD;
68
-
69
-    /**
70
-     * The request URI
71
-     *
72
-     * @var UriInterface
73
-     */
74
-    private UriInterface $uri;
75
-
76
-    /**
77
-     * The request target
78
-     *
79
-     * @var string|null
80
-     */
81
-    private ?string $requestTarget = null;
82
-
83
-    /**
84
-     * Constructor of the class
85
-     *
86
-     * @param string|null $method
87
-     * @param mixed $uri
88
-     * @param array<string, string|string[]>|null $headers
89
-     * @param StreamInterface|null $body
90
-     *
91
-     * @throws InvalidArgumentException
92
-     *         If one of the arguments isn't valid.
93
-     */
94
-    public function __construct(
95
-        ?string $method = null,
96
-        $uri = null,
97
-        ?array $headers = null,
98
-        ?StreamInterface $body = null
99
-    ) {
100
-        if (isset($method)) {
101
-            $this->setMethod($method);
102
-        }
103
-
104
-        $this->setUri($uri ?? self::DEFAULT_URI);
105
-
106
-        if (isset($headers)) {
107
-            $this->setHeaders($headers);
108
-        }
109
-
110
-        if (isset($body)) {
111
-            $this->setBody($body);
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Gets the request method
117
-     *
118
-     * @return string
119
-     */
120
-    public function getMethod(): string
121
-    {
122
-        return $this->method;
123
-    }
124
-
125
-    /**
126
-     * Creates a new instance of the request with the given method
127
-     *
128
-     * @param string $method
129
-     *
130
-     * @return static
131
-     *
132
-     * @throws InvalidArgumentException
133
-     *         If the method isn't valid.
134
-     */
135
-    public function withMethod($method): RequestInterface
136
-    {
137
-        $clone = clone $this;
138
-        $clone->setMethod($method);
139
-
140
-        return $clone;
141
-    }
142
-
143
-    /**
144
-     * Gets the request URI
145
-     *
146
-     * @return UriInterface
147
-     */
148
-    public function getUri(): UriInterface
149
-    {
150
-        return $this->uri;
151
-    }
152
-
153
-    /**
154
-     * Creates a new instance of the request with the given URI
155
-     *
156
-     * @param UriInterface $uri
157
-     * @param bool $preserveHost
158
-     *
159
-     * @return static
160
-     */
161
-    public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
162
-    {
163
-        $clone = clone $this;
164
-        $clone->setUri($uri, $preserveHost);
165
-
166
-        return $clone;
167
-    }
168
-
169
-    /**
170
-     * Gets the request target
171
-     *
172
-     * @return string
173
-     */
174
-    public function getRequestTarget(): string
175
-    {
176
-        if (isset($this->requestTarget)) {
177
-            return $this->requestTarget;
178
-        }
179
-
180
-        $requestTarget = $this->uri->getPath();
181
-
182
-        // https://tools.ietf.org/html/rfc7230#section-5.3.1
183
-        // https://tools.ietf.org/html/rfc7230#section-2.7
184
-        //
185
-        // origin-form = absolute-path [ "?" query ]
186
-        // absolute-path = 1*( "/" segment )
187
-        if (strncmp($requestTarget, '/', 1) !== 0) {
188
-            return '/';
189
-        }
190
-
191
-        $queryString = $this->uri->getQuery();
192
-        if ($queryString !== '') {
193
-            $requestTarget .= '?' . $queryString;
194
-        }
195
-
196
-        return $requestTarget;
197
-    }
198
-
199
-    /**
200
-     * Creates a new instance of the request with the given request target
201
-     *
202
-     * @param mixed $requestTarget
203
-     *
204
-     * @return static
205
-     *
206
-     * @throws InvalidArgumentException
207
-     *         If the request target isn't valid.
208
-     */
209
-    public function withRequestTarget($requestTarget): RequestInterface
210
-    {
211
-        $clone = clone $this;
212
-        $clone->setRequestTarget($requestTarget);
213
-
214
-        return $clone;
215
-    }
216
-
217
-    /**
218
-     * Sets the given method to the request
219
-     *
220
-     * @param string $method
221
-     *
222
-     * @return void
223
-     *
224
-     * @throws InvalidArgumentException
225
-     *         If the method isn't valid.
226
-     */
227
-    final protected function setMethod($method): void
228
-    {
229
-        $this->validateMethod($method);
230
-
231
-        $this->method = $method;
232
-    }
233
-
234
-    /**
235
-     * Sets the given URI to the request
236
-     *
237
-     * @param mixed $uri
238
-     * @param bool $preserveHost
239
-     *
240
-     * @return void
241
-     *
242
-     * @throws InvalidArgumentException
243
-     *         If the URI isn't valid.
244
-     */
245
-    final protected function setUri($uri, $preserveHost = false): void
246
-    {
247
-        $this->uri = Uri::create($uri);
248
-
249
-        if ($preserveHost && $this->hasHeader('Host')) {
250
-            return;
251
-        }
252
-
253
-        $host = $this->uri->getHost();
254
-        if ($host === '') {
255
-            return;
256
-        }
257
-
258
-        $port = $this->uri->getPort();
259
-        if (isset($port)) {
260
-            $host .= ':' . $port;
261
-        }
262
-
263
-        $this->setHeader('Host', $host, true);
264
-    }
265
-
266
-    /**
267
-     * Sets the given request target to the request
268
-     *
269
-     * @param mixed $requestTarget
270
-     *
271
-     * @return void
272
-     *
273
-     * @throws InvalidArgumentException
274
-     *         If the request target isn't valid.
275
-     */
276
-    final protected function setRequestTarget($requestTarget): void
277
-    {
278
-        $this->validateRequestTarget($requestTarget);
279
-
280
-        /** @var string $requestTarget */
281
-
282
-        $this->requestTarget = $requestTarget;
283
-    }
284
-
285
-    /**
286
-     * Validates the given method
287
-     *
288
-     * @link https://tools.ietf.org/html/rfc7230#section-3.1.1
289
-     *
290
-     * @param mixed $method
291
-     *
292
-     * @return void
293
-     *
294
-     * @throws InvalidArgumentException
295
-     *         If the method isn't valid.
296
-     */
297
-    private function validateMethod($method): void
298
-    {
299
-        if ('' === $method) {
300
-            throw new InvalidArgumentException('HTTP method cannot be an empty');
301
-        }
302
-
303
-        if (!is_string($method)) {
304
-            throw new InvalidArgumentException('HTTP method must be a string');
305
-        }
306
-
307
-        if (!preg_match(Header::RFC7230_VALID_TOKEN, $method)) {
308
-            throw new InvalidArgumentException('Invalid HTTP method');
309
-        }
310
-    }
311
-
312
-    /**
313
-     * Validates the given request target
314
-     *
315
-     * @param mixed $requestTarget
316
-     *
317
-     * @return void
318
-     *
319
-     * @throws InvalidArgumentException
320
-     *         If the request target isn't valid.
321
-     */
322
-    private function validateRequestTarget($requestTarget): void
323
-    {
324
-        if ('' === $requestTarget) {
325
-            throw new InvalidArgumentException('HTTP request target cannot be an empty');
326
-        }
327
-
328
-        if (!is_string($requestTarget)) {
329
-            throw new InvalidArgumentException('HTTP request target must be a string');
330
-        }
331
-
332
-        if (!preg_match(self::RFC7230_VALID_REQUEST_TARGET, $requestTarget)) {
333
-            throw new InvalidArgumentException('Invalid HTTP request target');
334
-        }
335
-    }
39
+	/**
40
+	 * Regular Expression for a request target validation
41
+	 *
42
+	 * @link https://tools.ietf.org/html/rfc7230#section-5.3
43
+	 *
44
+	 * @var string
45
+	 */
46
+	public const RFC7230_VALID_REQUEST_TARGET = '/^[\x21-\x7E\x80-\xFF]+$/';
47
+
48
+	/**
49
+	 * Default request method
50
+	 *
51
+	 * @var string
52
+	 */
53
+	public const DEFAULT_METHOD = self::METHOD_GET;
54
+
55
+	/**
56
+	 * Default request URI
57
+	 *
58
+	 * @var string
59
+	 */
60
+	public const DEFAULT_URI = '/';
61
+
62
+	/**
63
+	 * The request method (aka verb)
64
+	 *
65
+	 * @var string
66
+	 */
67
+	private string $method = self::DEFAULT_METHOD;
68
+
69
+	/**
70
+	 * The request URI
71
+	 *
72
+	 * @var UriInterface
73
+	 */
74
+	private UriInterface $uri;
75
+
76
+	/**
77
+	 * The request target
78
+	 *
79
+	 * @var string|null
80
+	 */
81
+	private ?string $requestTarget = null;
82
+
83
+	/**
84
+	 * Constructor of the class
85
+	 *
86
+	 * @param string|null $method
87
+	 * @param mixed $uri
88
+	 * @param array<string, string|string[]>|null $headers
89
+	 * @param StreamInterface|null $body
90
+	 *
91
+	 * @throws InvalidArgumentException
92
+	 *         If one of the arguments isn't valid.
93
+	 */
94
+	public function __construct(
95
+		?string $method = null,
96
+		$uri = null,
97
+		?array $headers = null,
98
+		?StreamInterface $body = null
99
+	) {
100
+		if (isset($method)) {
101
+			$this->setMethod($method);
102
+		}
103
+
104
+		$this->setUri($uri ?? self::DEFAULT_URI);
105
+
106
+		if (isset($headers)) {
107
+			$this->setHeaders($headers);
108
+		}
109
+
110
+		if (isset($body)) {
111
+			$this->setBody($body);
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Gets the request method
117
+	 *
118
+	 * @return string
119
+	 */
120
+	public function getMethod(): string
121
+	{
122
+		return $this->method;
123
+	}
124
+
125
+	/**
126
+	 * Creates a new instance of the request with the given method
127
+	 *
128
+	 * @param string $method
129
+	 *
130
+	 * @return static
131
+	 *
132
+	 * @throws InvalidArgumentException
133
+	 *         If the method isn't valid.
134
+	 */
135
+	public function withMethod($method): RequestInterface
136
+	{
137
+		$clone = clone $this;
138
+		$clone->setMethod($method);
139
+
140
+		return $clone;
141
+	}
142
+
143
+	/**
144
+	 * Gets the request URI
145
+	 *
146
+	 * @return UriInterface
147
+	 */
148
+	public function getUri(): UriInterface
149
+	{
150
+		return $this->uri;
151
+	}
152
+
153
+	/**
154
+	 * Creates a new instance of the request with the given URI
155
+	 *
156
+	 * @param UriInterface $uri
157
+	 * @param bool $preserveHost
158
+	 *
159
+	 * @return static
160
+	 */
161
+	public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
162
+	{
163
+		$clone = clone $this;
164
+		$clone->setUri($uri, $preserveHost);
165
+
166
+		return $clone;
167
+	}
168
+
169
+	/**
170
+	 * Gets the request target
171
+	 *
172
+	 * @return string
173
+	 */
174
+	public function getRequestTarget(): string
175
+	{
176
+		if (isset($this->requestTarget)) {
177
+			return $this->requestTarget;
178
+		}
179
+
180
+		$requestTarget = $this->uri->getPath();
181
+
182
+		// https://tools.ietf.org/html/rfc7230#section-5.3.1
183
+		// https://tools.ietf.org/html/rfc7230#section-2.7
184
+		//
185
+		// origin-form = absolute-path [ "?" query ]
186
+		// absolute-path = 1*( "/" segment )
187
+		if (strncmp($requestTarget, '/', 1) !== 0) {
188
+			return '/';
189
+		}
190
+
191
+		$queryString = $this->uri->getQuery();
192
+		if ($queryString !== '') {
193
+			$requestTarget .= '?' . $queryString;
194
+		}
195
+
196
+		return $requestTarget;
197
+	}
198
+
199
+	/**
200
+	 * Creates a new instance of the request with the given request target
201
+	 *
202
+	 * @param mixed $requestTarget
203
+	 *
204
+	 * @return static
205
+	 *
206
+	 * @throws InvalidArgumentException
207
+	 *         If the request target isn't valid.
208
+	 */
209
+	public function withRequestTarget($requestTarget): RequestInterface
210
+	{
211
+		$clone = clone $this;
212
+		$clone->setRequestTarget($requestTarget);
213
+
214
+		return $clone;
215
+	}
216
+
217
+	/**
218
+	 * Sets the given method to the request
219
+	 *
220
+	 * @param string $method
221
+	 *
222
+	 * @return void
223
+	 *
224
+	 * @throws InvalidArgumentException
225
+	 *         If the method isn't valid.
226
+	 */
227
+	final protected function setMethod($method): void
228
+	{
229
+		$this->validateMethod($method);
230
+
231
+		$this->method = $method;
232
+	}
233
+
234
+	/**
235
+	 * Sets the given URI to the request
236
+	 *
237
+	 * @param mixed $uri
238
+	 * @param bool $preserveHost
239
+	 *
240
+	 * @return void
241
+	 *
242
+	 * @throws InvalidArgumentException
243
+	 *         If the URI isn't valid.
244
+	 */
245
+	final protected function setUri($uri, $preserveHost = false): void
246
+	{
247
+		$this->uri = Uri::create($uri);
248
+
249
+		if ($preserveHost && $this->hasHeader('Host')) {
250
+			return;
251
+		}
252
+
253
+		$host = $this->uri->getHost();
254
+		if ($host === '') {
255
+			return;
256
+		}
257
+
258
+		$port = $this->uri->getPort();
259
+		if (isset($port)) {
260
+			$host .= ':' . $port;
261
+		}
262
+
263
+		$this->setHeader('Host', $host, true);
264
+	}
265
+
266
+	/**
267
+	 * Sets the given request target to the request
268
+	 *
269
+	 * @param mixed $requestTarget
270
+	 *
271
+	 * @return void
272
+	 *
273
+	 * @throws InvalidArgumentException
274
+	 *         If the request target isn't valid.
275
+	 */
276
+	final protected function setRequestTarget($requestTarget): void
277
+	{
278
+		$this->validateRequestTarget($requestTarget);
279
+
280
+		/** @var string $requestTarget */
281
+
282
+		$this->requestTarget = $requestTarget;
283
+	}
284
+
285
+	/**
286
+	 * Validates the given method
287
+	 *
288
+	 * @link https://tools.ietf.org/html/rfc7230#section-3.1.1
289
+	 *
290
+	 * @param mixed $method
291
+	 *
292
+	 * @return void
293
+	 *
294
+	 * @throws InvalidArgumentException
295
+	 *         If the method isn't valid.
296
+	 */
297
+	private function validateMethod($method): void
298
+	{
299
+		if ('' === $method) {
300
+			throw new InvalidArgumentException('HTTP method cannot be an empty');
301
+		}
302
+
303
+		if (!is_string($method)) {
304
+			throw new InvalidArgumentException('HTTP method must be a string');
305
+		}
306
+
307
+		if (!preg_match(Header::RFC7230_VALID_TOKEN, $method)) {
308
+			throw new InvalidArgumentException('Invalid HTTP method');
309
+		}
310
+	}
311
+
312
+	/**
313
+	 * Validates the given request target
314
+	 *
315
+	 * @param mixed $requestTarget
316
+	 *
317
+	 * @return void
318
+	 *
319
+	 * @throws InvalidArgumentException
320
+	 *         If the request target isn't valid.
321
+	 */
322
+	private function validateRequestTarget($requestTarget): void
323
+	{
324
+		if ('' === $requestTarget) {
325
+			throw new InvalidArgumentException('HTTP request target cannot be an empty');
326
+		}
327
+
328
+		if (!is_string($requestTarget)) {
329
+			throw new InvalidArgumentException('HTTP request target must be a string');
330
+		}
331
+
332
+		if (!preg_match(self::RFC7230_VALID_REQUEST_TARGET, $requestTarget)) {
333
+			throw new InvalidArgumentException('Invalid HTTP request target');
334
+		}
335
+	}
336 336
 }
Please login to merge, or discard this patch.
src/Uri/Component/UserInfo.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -19,48 +19,48 @@
 block discarded – undo
19 19
 final class UserInfo implements ComponentInterface
20 20
 {
21 21
 
22
-    /**
23
-     * URI component "user"
24
-     *
25
-     * @var User
26
-     */
27
-    private User $user;
22
+	/**
23
+	 * URI component "user"
24
+	 *
25
+	 * @var User
26
+	 */
27
+	private User $user;
28 28
 
29
-    /**
30
-     * URI component "password"
31
-     *
32
-     * @var Password|null
33
-     */
34
-    private ?Password $password = null;
29
+	/**
30
+	 * URI component "password"
31
+	 *
32
+	 * @var Password|null
33
+	 */
34
+	private ?Password $password = null;
35 35
 
36
-    /**
37
-     * Constructor of the class
38
-     *
39
-     * @param mixed $user
40
-     * @param mixed $password
41
-     */
42
-    public function __construct($user, $password = null)
43
-    {
44
-        $this->user = User::create($user);
36
+	/**
37
+	 * Constructor of the class
38
+	 *
39
+	 * @param mixed $user
40
+	 * @param mixed $password
41
+	 */
42
+	public function __construct($user, $password = null)
43
+	{
44
+		$this->user = User::create($user);
45 45
 
46
-        if (isset($password)) {
47
-            $this->password = Password::create($password);
48
-        }
49
-    }
46
+		if (isset($password)) {
47
+			$this->password = Password::create($password);
48
+		}
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritdoc}
53
-     *
54
-     * @return string
55
-     */
56
-    public function getValue(): string
57
-    {
58
-        $value = $this->user->getValue();
51
+	/**
52
+	 * {@inheritdoc}
53
+	 *
54
+	 * @return string
55
+	 */
56
+	public function getValue(): string
57
+	{
58
+		$value = $this->user->getValue();
59 59
 
60
-        if (isset($this->password)) {
61
-            $value .= ':' . $this->password->getValue();
62
-        }
60
+		if (isset($this->password)) {
61
+			$value .= ':' . $this->password->getValue();
62
+		}
63 63
 
64
-        return $value;
65
-    }
64
+		return $value;
65
+	}
66 66
 }
Please login to merge, or discard this patch.