Passed
Pull Request — master (#31)
by Anatoly
03:57
created
src/Stream/PhpMemoryStream.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@
 block discarded – undo
27 27
 final class PhpMemoryStream extends Stream
28 28
 {
29 29
 
30
-    /**
31
-     * Constructor of the class
32
-     *
33
-     * @param string $mode
34
-     */
35
-    public function __construct(string $mode = 'r+b')
36
-    {
37
-        parent::__construct(fopen('php://memory', $mode));
38
-    }
30
+	/**
31
+	 * Constructor of the class
32
+	 *
33
+	 * @param string $mode
34
+	 */
35
+	public function __construct(string $mode = 'r+b')
36
+	{
37
+		parent::__construct(fopen('php://memory', $mode));
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Stream/TmpfileStream.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -35,23 +35,23 @@
 block discarded – undo
35 35
 final class TmpfileStream extends Stream
36 36
 {
37 37
 
38
-    /**
39
-     * Constructor of the class
40
-     *
41
-     * @throws RuntimeException
42
-     */
43
-    public function __construct()
44
-    {
45
-        $dirname = sys_get_temp_dir();
46
-        if (!is_writable($dirname)) {
47
-            throw new RuntimeException('Temporary files directory is not writable');
48
-        }
49
-
50
-        $resource = tmpfile();
51
-        if (!is_resource($resource)) {
52
-            throw new RuntimeException('Temporary file cannot be created or opened');
53
-        }
54
-
55
-        parent::__construct($resource);
56
-    }
38
+	/**
39
+	 * Constructor of the class
40
+	 *
41
+	 * @throws RuntimeException
42
+	 */
43
+	public function __construct()
44
+	{
45
+		$dirname = sys_get_temp_dir();
46
+		if (!is_writable($dirname)) {
47
+			throw new RuntimeException('Temporary files directory is not writable');
48
+		}
49
+
50
+		$resource = tmpfile();
51
+		if (!is_resource($resource)) {
52
+			throw new RuntimeException('Temporary file cannot be created or opened');
53
+		}
54
+
55
+		parent::__construct($resource);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
src/Response.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -35,241 +35,241 @@
 block discarded – undo
35 35
 class Response extends Message implements ResponseInterface, StatusCodeInterface
36 36
 {
37 37
 
38
-    /**
39
-     * List of Reason Phrases
40
-     *
41
-     * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
42
-     *
43
-     * @var array<int<100, 599>, non-empty-string>
44
-     */
45
-    public const REASON_PHRASES = [
38
+	/**
39
+	 * List of Reason Phrases
40
+	 *
41
+	 * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
42
+	 *
43
+	 * @var array<int<100, 599>, non-empty-string>
44
+	 */
45
+	public const REASON_PHRASES = [
46 46
 
47
-        // 1xx
48
-        100 => 'Continue',
49
-        101 => 'Switching Protocols',
50
-        102 => 'Processing',
51
-        103 => 'Early Hints',
47
+		// 1xx
48
+		100 => 'Continue',
49
+		101 => 'Switching Protocols',
50
+		102 => 'Processing',
51
+		103 => 'Early Hints',
52 52
 
53
-        // 2xx
54
-        200 => 'OK',
55
-        201 => 'Created',
56
-        202 => 'Accepted',
57
-        203 => 'Non-Authoritative Information',
58
-        204 => 'No Content',
59
-        205 => 'Reset Content',
60
-        206 => 'Partial Content',
61
-        207 => 'Multi-Status',
62
-        208 => 'Already Reported',
63
-        226 => 'IM Used',
53
+		// 2xx
54
+		200 => 'OK',
55
+		201 => 'Created',
56
+		202 => 'Accepted',
57
+		203 => 'Non-Authoritative Information',
58
+		204 => 'No Content',
59
+		205 => 'Reset Content',
60
+		206 => 'Partial Content',
61
+		207 => 'Multi-Status',
62
+		208 => 'Already Reported',
63
+		226 => 'IM Used',
64 64
 
65
-        // 3xx
66
-        300 => 'Multiple Choices',
67
-        301 => 'Moved Permanently',
68
-        302 => 'Found',
69
-        303 => 'See Other',
70
-        304 => 'Not Modified',
71
-        305 => 'Use Proxy',
72
-        307 => 'Temporary Redirect',
73
-        308 => 'Permanent Redirect',
65
+		// 3xx
66
+		300 => 'Multiple Choices',
67
+		301 => 'Moved Permanently',
68
+		302 => 'Found',
69
+		303 => 'See Other',
70
+		304 => 'Not Modified',
71
+		305 => 'Use Proxy',
72
+		307 => 'Temporary Redirect',
73
+		308 => 'Permanent Redirect',
74 74
 
75
-        // 4xx
76
-        400 => 'Bad Request',
77
-        401 => 'Unauthorized',
78
-        402 => 'Payment Required',
79
-        403 => 'Forbidden',
80
-        404 => 'Not Found',
81
-        405 => 'Method Not Allowed',
82
-        406 => 'Not Acceptable',
83
-        407 => 'Proxy Authentication Required',
84
-        408 => 'Request Timeout',
85
-        409 => 'Conflict',
86
-        410 => 'Gone',
87
-        411 => 'Length Required',
88
-        412 => 'Precondition Failed',
89
-        413 => 'Payload Too Large',
90
-        414 => 'URI Too Long',
91
-        415 => 'Unsupported Media Type',
92
-        416 => 'Range Not Satisfiable',
93
-        417 => 'Expectation Failed',
94
-        421 => 'Misdirected Request',
95
-        422 => 'Unprocessable Entity',
96
-        423 => 'Locked',
97
-        424 => 'Failed Dependency',
98
-        425 => 'Too Early',
99
-        426 => 'Upgrade Required',
100
-        428 => 'Precondition Required',
101
-        429 => 'Too Many Requests',
102
-        431 => 'Request Header Fields Too Large',
103
-        451 => 'Unavailable For Legal Reasons',
75
+		// 4xx
76
+		400 => 'Bad Request',
77
+		401 => 'Unauthorized',
78
+		402 => 'Payment Required',
79
+		403 => 'Forbidden',
80
+		404 => 'Not Found',
81
+		405 => 'Method Not Allowed',
82
+		406 => 'Not Acceptable',
83
+		407 => 'Proxy Authentication Required',
84
+		408 => 'Request Timeout',
85
+		409 => 'Conflict',
86
+		410 => 'Gone',
87
+		411 => 'Length Required',
88
+		412 => 'Precondition Failed',
89
+		413 => 'Payload Too Large',
90
+		414 => 'URI Too Long',
91
+		415 => 'Unsupported Media Type',
92
+		416 => 'Range Not Satisfiable',
93
+		417 => 'Expectation Failed',
94
+		421 => 'Misdirected Request',
95
+		422 => 'Unprocessable Entity',
96
+		423 => 'Locked',
97
+		424 => 'Failed Dependency',
98
+		425 => 'Too Early',
99
+		426 => 'Upgrade Required',
100
+		428 => 'Precondition Required',
101
+		429 => 'Too Many Requests',
102
+		431 => 'Request Header Fields Too Large',
103
+		451 => 'Unavailable For Legal Reasons',
104 104
 
105
-        // 5xx
106
-        500 => 'Internal Server Error',
107
-        501 => 'Not Implemented',
108
-        502 => 'Bad Gateway',
109
-        503 => 'Service Unavailable',
110
-        504 => 'Gateway Timeout',
111
-        505 => 'HTTP Version Not Supported',
112
-        506 => 'Variant Also Negotiates',
113
-        507 => 'Insufficient Storage',
114
-        508 => 'Loop Detected',
115
-        510 => 'Not Extended',
116
-        511 => 'Network Authentication Required',
117
-    ];
105
+		// 5xx
106
+		500 => 'Internal Server Error',
107
+		501 => 'Not Implemented',
108
+		502 => 'Bad Gateway',
109
+		503 => 'Service Unavailable',
110
+		504 => 'Gateway Timeout',
111
+		505 => 'HTTP Version Not Supported',
112
+		506 => 'Variant Also Negotiates',
113
+		507 => 'Insufficient Storage',
114
+		508 => 'Loop Detected',
115
+		510 => 'Not Extended',
116
+		511 => 'Network Authentication Required',
117
+	];
118 118
 
119
-    /**
120
-     * The response's status code
121
-     *
122
-     * @var int
123
-     */
124
-    private int $statusCode = self::STATUS_OK;
119
+	/**
120
+	 * The response's status code
121
+	 *
122
+	 * @var int
123
+	 */
124
+	private int $statusCode = self::STATUS_OK;
125 125
 
126
-    /**
127
-     * The response's reason phrase
128
-     *
129
-     * @var string
130
-     */
131
-    private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK];
126
+	/**
127
+	 * The response's reason phrase
128
+	 *
129
+	 * @var string
130
+	 */
131
+	private string $reasonPhrase = self::REASON_PHRASES[self::STATUS_OK];
132 132
 
133
-    /**
134
-     * Constrictor of the class
135
-     *
136
-     * @param int|null $statusCode
137
-     * @param string|null $reasonPhrase
138
-     * @param array<string, string|string[]>|null $headers
139
-     * @param StreamInterface|null $body
140
-     *
141
-     * @throws InvalidArgumentException
142
-     *         If one of the arguments isn't valid.
143
-     */
144
-    public function __construct(
145
-        ?int $statusCode = null,
146
-        ?string $reasonPhrase = null,
147
-        ?array $headers = null,
148
-        ?StreamInterface $body = null
149
-    ) {
150
-        if (isset($statusCode)) {
151
-            $this->setStatus($statusCode, $reasonPhrase ?? '');
152
-        }
133
+	/**
134
+	 * Constrictor of the class
135
+	 *
136
+	 * @param int|null $statusCode
137
+	 * @param string|null $reasonPhrase
138
+	 * @param array<string, string|string[]>|null $headers
139
+	 * @param StreamInterface|null $body
140
+	 *
141
+	 * @throws InvalidArgumentException
142
+	 *         If one of the arguments isn't valid.
143
+	 */
144
+	public function __construct(
145
+		?int $statusCode = null,
146
+		?string $reasonPhrase = null,
147
+		?array $headers = null,
148
+		?StreamInterface $body = null
149
+	) {
150
+		if (isset($statusCode)) {
151
+			$this->setStatus($statusCode, $reasonPhrase ?? '');
152
+		}
153 153
 
154
-        if (isset($headers)) {
155
-            $this->setHeaders($headers);
156
-        }
154
+		if (isset($headers)) {
155
+			$this->setHeaders($headers);
156
+		}
157 157
 
158
-        if (isset($body)) {
159
-            $this->setBody($body);
160
-        }
161
-    }
158
+		if (isset($body)) {
159
+			$this->setBody($body);
160
+		}
161
+	}
162 162
 
163
-    /**
164
-     * Gets the response's status code
165
-     *
166
-     * @return int
167
-     */
168
-    public function getStatusCode(): int
169
-    {
170
-        return $this->statusCode;
171
-    }
163
+	/**
164
+	 * Gets the response's status code
165
+	 *
166
+	 * @return int
167
+	 */
168
+	public function getStatusCode(): int
169
+	{
170
+		return $this->statusCode;
171
+	}
172 172
 
173
-    /**
174
-     * Gets the response's reason phrase
175
-     *
176
-     * @return string
177
-     */
178
-    public function getReasonPhrase(): string
179
-    {
180
-        return $this->reasonPhrase;
181
-    }
173
+	/**
174
+	 * Gets the response's reason phrase
175
+	 *
176
+	 * @return string
177
+	 */
178
+	public function getReasonPhrase(): string
179
+	{
180
+		return $this->reasonPhrase;
181
+	}
182 182
 
183
-    /**
184
-     * Creates a new instance of the response with the given status code
185
-     *
186
-     * @param int $code
187
-     * @param string $reasonPhrase
188
-     *
189
-     * @return static
190
-     *
191
-     * @throws InvalidArgumentException
192
-     *         If the status isn't valid.
193
-     */
194
-    public function withStatus($code, $reasonPhrase = ''): ResponseInterface
195
-    {
196
-        $clone = clone $this;
197
-        $clone->setStatus($code, $reasonPhrase);
183
+	/**
184
+	 * Creates a new instance of the response with the given status code
185
+	 *
186
+	 * @param int $code
187
+	 * @param string $reasonPhrase
188
+	 *
189
+	 * @return static
190
+	 *
191
+	 * @throws InvalidArgumentException
192
+	 *         If the status isn't valid.
193
+	 */
194
+	public function withStatus($code, $reasonPhrase = ''): ResponseInterface
195
+	{
196
+		$clone = clone $this;
197
+		$clone->setStatus($code, $reasonPhrase);
198 198
 
199
-        return $clone;
200
-    }
199
+		return $clone;
200
+	}
201 201
 
202
-    /**
203
-     * Sets the given status code to the response
204
-     *
205
-     * @param int $statusCode
206
-     * @param string $reasonPhrase
207
-     *
208
-     * @return void
209
-     *
210
-     * @throws InvalidArgumentException
211
-     *         If the status isn't valid.
212
-     */
213
-    final protected function setStatus($statusCode, $reasonPhrase): void
214
-    {
215
-        $this->validateStatusCode($statusCode);
216
-        $this->validateReasonPhrase($reasonPhrase);
202
+	/**
203
+	 * Sets the given status code to the response
204
+	 *
205
+	 * @param int $statusCode
206
+	 * @param string $reasonPhrase
207
+	 *
208
+	 * @return void
209
+	 *
210
+	 * @throws InvalidArgumentException
211
+	 *         If the status isn't valid.
212
+	 */
213
+	final protected function setStatus($statusCode, $reasonPhrase): void
214
+	{
215
+		$this->validateStatusCode($statusCode);
216
+		$this->validateReasonPhrase($reasonPhrase);
217 217
 
218
-        if ('' === $reasonPhrase) {
219
-            $reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code';
220
-        }
218
+		if ('' === $reasonPhrase) {
219
+			$reasonPhrase = self::REASON_PHRASES[$statusCode] ?? 'Unknown Status Code';
220
+		}
221 221
 
222
-        $this->statusCode = $statusCode;
223
-        $this->reasonPhrase = $reasonPhrase;
224
-    }
222
+		$this->statusCode = $statusCode;
223
+		$this->reasonPhrase = $reasonPhrase;
224
+	}
225 225
 
226
-    /**
227
-     * Validates the given status code
228
-     *
229
-     * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
230
-     *
231
-     * @param mixed $statusCode
232
-     *
233
-     * @return void
234
-     *
235
-     * @throws InvalidArgumentException
236
-     *         If the status code isn't valid.
237
-     */
238
-    private function validateStatusCode($statusCode): void
239
-    {
240
-        if (!is_int($statusCode)) {
241
-            throw new InvalidArgumentException('HTTP status code must be an integer');
242
-        }
226
+	/**
227
+	 * Validates the given status code
228
+	 *
229
+	 * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
230
+	 *
231
+	 * @param mixed $statusCode
232
+	 *
233
+	 * @return void
234
+	 *
235
+	 * @throws InvalidArgumentException
236
+	 *         If the status code isn't valid.
237
+	 */
238
+	private function validateStatusCode($statusCode): void
239
+	{
240
+		if (!is_int($statusCode)) {
241
+			throw new InvalidArgumentException('HTTP status code must be an integer');
242
+		}
243 243
 
244
-        if (! ($statusCode >= 100 && $statusCode <= 599)) {
245
-            throw new InvalidArgumentException('Invalid HTTP status code');
246
-        }
247
-    }
244
+		if (! ($statusCode >= 100 && $statusCode <= 599)) {
245
+			throw new InvalidArgumentException('Invalid HTTP status code');
246
+		}
247
+	}
248 248
 
249
-    /**
250
-     * Validates the given reason phrase
251
-     *
252
-     * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
253
-     *
254
-     * @param mixed $reasonPhrase
255
-     *
256
-     * @return void
257
-     *
258
-     * @throws InvalidArgumentException
259
-     *         If the reason phrase isn't valid.
260
-     */
261
-    private function validateReasonPhrase($reasonPhrase): void
262
-    {
263
-        if ('' === $reasonPhrase) {
264
-            return;
265
-        }
249
+	/**
250
+	 * Validates the given reason phrase
251
+	 *
252
+	 * @link https://tools.ietf.org/html/rfc7230#section-3.1.2
253
+	 *
254
+	 * @param mixed $reasonPhrase
255
+	 *
256
+	 * @return void
257
+	 *
258
+	 * @throws InvalidArgumentException
259
+	 *         If the reason phrase isn't valid.
260
+	 */
261
+	private function validateReasonPhrase($reasonPhrase): void
262
+	{
263
+		if ('' === $reasonPhrase) {
264
+			return;
265
+		}
266 266
 
267
-        if (!is_string($reasonPhrase)) {
268
-            throw new InvalidArgumentException('HTTP reason phrase must be a string');
269
-        }
267
+		if (!is_string($reasonPhrase)) {
268
+			throw new InvalidArgumentException('HTTP reason phrase must be a string');
269
+		}
270 270
 
271
-        if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) {
272
-            throw new InvalidArgumentException('Invalid HTTP reason phrase');
273
-        }
274
-    }
271
+		if (!preg_match(HeaderInterface::RFC7230_FIELD_VALUE_REGEX, $reasonPhrase)) {
272
+			throw new InvalidArgumentException('Invalid HTTP reason phrase');
273
+		}
274
+	}
275 275
 }
Please login to merge, or discard this patch.
src/HeaderInterface.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -22,52 +22,52 @@
 block discarded – undo
22 22
 interface HeaderInterface extends IteratorAggregate
23 23
 {
24 24
 
25
-    /**
26
-     * Date format according to RFC-822
27
-     *
28
-     * @var string
29
-     */
30
-    public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';
25
+	/**
26
+	 * Date format according to RFC-822
27
+	 *
28
+	 * @var string
29
+	 */
30
+	public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';
31 31
 
32
-    /**
33
-     * Regular Expression used for a token validation according to RFC-7230
34
-     *
35
-     * @var string
36
-     */
37
-    public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/';
32
+	/**
33
+	 * Regular Expression used for a token validation according to RFC-7230
34
+	 *
35
+	 * @var string
36
+	 */
37
+	public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/';
38 38
 
39
-    /**
40
-     * Regular Expression used for a field-value validation according to RFC-7230
41
-     *
42
-     * @var string
43
-     */
44
-    public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/';
39
+	/**
40
+	 * Regular Expression used for a field-value validation according to RFC-7230
41
+	 *
42
+	 * @var string
43
+	 */
44
+	public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/';
45 45
 
46
-    /**
47
-     * Regular Expression used for a quoted-string validation according to RFC-7230
48
-     *
49
-     * @var string
50
-     */
51
-    public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/';
46
+	/**
47
+	 * Regular Expression used for a quoted-string validation according to RFC-7230
48
+	 *
49
+	 * @var string
50
+	 */
51
+	public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/';
52 52
 
53
-    /**
54
-     * Gets the header field name
55
-     *
56
-     * @return string
57
-     */
58
-    public function getFieldName(): string;
53
+	/**
54
+	 * Gets the header field name
55
+	 *
56
+	 * @return string
57
+	 */
58
+	public function getFieldName(): string;
59 59
 
60
-    /**
61
-     * Gets the header field value
62
-     *
63
-     * @return string
64
-     */
65
-    public function getFieldValue(): string;
60
+	/**
61
+	 * Gets the header field value
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function getFieldValue(): string;
66 66
 
67
-    /**
68
-     * Converts the header to a field
69
-     *
70
-     * @return string
71
-     */
72
-    public function __toString(): string;
67
+	/**
68
+	 * Converts the header to a field
69
+	 *
70
+	 * @return string
71
+	 */
72
+	public function __toString(): string;
73 73
 }
Please login to merge, or discard this patch.
src/Stream/PhpTempStream.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@
 block discarded – undo
28 28
 final class PhpTempStream extends Stream
29 29
 {
30 30
 
31
-    /**
32
-     * Constructor of the class
33
-     *
34
-     * @param string $mode
35
-     * @param int<0, max> $maxmemory
36
-     */
37
-    public function __construct(string $mode = 'r+b', int $maxmemory = 2097152)
38
-    {
39
-        parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode));
40
-    }
31
+	/**
32
+	 * Constructor of the class
33
+	 *
34
+	 * @param string $mode
35
+	 * @param int<0, max> $maxmemory
36
+	 */
37
+	public function __construct(string $mode = 'r+b', int $maxmemory = 2097152)
38
+	{
39
+		parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode));
40
+	}
41 41
 }
Please login to merge, or discard this patch.
src/Stream/TempFileStream.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -32,30 +32,30 @@
 block discarded – undo
32 32
 final class TempFileStream extends Stream
33 33
 {
34 34
 
35
-    /**
36
-     * Constructor of the class
37
-     *
38
-     * @param string $prefix
39
-     *
40
-     * @throws RuntimeException
41
-     */
42
-    public function __construct(string $prefix = '')
43
-    {
44
-        $dirname = sys_get_temp_dir();
45
-        if (!is_writable($dirname)) {
46
-            throw new RuntimeException('Temporary files directory is not writable');
47
-        }
48
-
49
-        $filename = tempnam($dirname, $prefix);
50
-        if ($filename === false) {
51
-            throw new RuntimeException('Temporary file name cannot be generated');
52
-        }
53
-
54
-        $resource = fopen($filename, 'w+b');
55
-        if (!is_resource($resource)) {
56
-            throw new RuntimeException('Temporary file cannot be created or opened');
57
-        }
58
-
59
-        parent::__construct($resource);
60
-    }
35
+	/**
36
+	 * Constructor of the class
37
+	 *
38
+	 * @param string $prefix
39
+	 *
40
+	 * @throws RuntimeException
41
+	 */
42
+	public function __construct(string $prefix = '')
43
+	{
44
+		$dirname = sys_get_temp_dir();
45
+		if (!is_writable($dirname)) {
46
+			throw new RuntimeException('Temporary files directory is not writable');
47
+		}
48
+
49
+		$filename = tempnam($dirname, $prefix);
50
+		if ($filename === false) {
51
+			throw new RuntimeException('Temporary file name cannot be generated');
52
+		}
53
+
54
+		$resource = fopen($filename, 'w+b');
55
+		if (!is_resource($resource)) {
56
+			throw new RuntimeException('Temporary file cannot be created or opened');
57
+		}
58
+
59
+		parent::__construct($resource);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
src/Response/HtmlResponse.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
 final class HtmlResponse extends Response
33 33
 {
34 34
 
35
-    /**
36
-     * Constructor of the class
37
-     *
38
-     * @param int $statusCode
39
-     * @param mixed $html
40
-     *
41
-     * @throws InvalidArgumentException
42
-     */
43
-    public function __construct(int $statusCode, $html)
44
-    {
45
-        parent::__construct($statusCode);
35
+	/**
36
+	 * Constructor of the class
37
+	 *
38
+	 * @param int $statusCode
39
+	 * @param mixed $html
40
+	 *
41
+	 * @throws InvalidArgumentException
42
+	 */
43
+	public function __construct(int $statusCode, $html)
44
+	{
45
+		parent::__construct($statusCode);
46 46
 
47
-        $this->setBody($this->createBody($html));
47
+		$this->setBody($this->createBody($html));
48 48
 
49
-        $this->setHeader('Content-Type', 'text/html; charset=utf-8');
50
-    }
49
+		$this->setHeader('Content-Type', 'text/html; charset=utf-8');
50
+	}
51 51
 
52
-    /**
53
-     * Creates the response body from the given HTML data
54
-     *
55
-     * @param mixed $html
56
-     *
57
-     * @return StreamInterface
58
-     *
59
-     * @throws InvalidArgumentException
60
-     */
61
-    private function createBody($html): StreamInterface
62
-    {
63
-        if ($html instanceof StreamInterface) {
64
-            return $html;
65
-        }
52
+	/**
53
+	 * Creates the response body from the given HTML data
54
+	 *
55
+	 * @param mixed $html
56
+	 *
57
+	 * @return StreamInterface
58
+	 *
59
+	 * @throws InvalidArgumentException
60
+	 */
61
+	private function createBody($html): StreamInterface
62
+	{
63
+		if ($html instanceof StreamInterface) {
64
+			return $html;
65
+		}
66 66
 
67
-        if (is_object($html) && method_exists($html, '__toString')) {
68
-            /** @var string */
69
-            $html = $html->__toString();
70
-        }
67
+		if (is_object($html) && method_exists($html, '__toString')) {
68
+			/** @var string */
69
+			$html = $html->__toString();
70
+		}
71 71
 
72
-        if (!is_string($html)) {
73
-            throw new InvalidArgumentException('Unable to create HTML response due to unexpected HTML data');
74
-        }
72
+		if (!is_string($html)) {
73
+			throw new InvalidArgumentException('Unable to create HTML response due to unexpected HTML data');
74
+		}
75 75
 
76
-        $stream = new PhpTempStream('r+b');
77
-        $stream->write($html);
78
-        $stream->rewind();
76
+		$stream = new PhpTempStream('r+b');
77
+		$stream->write($html);
78
+		$stream->rewind();
79 79
 
80
-        return $stream;
81
-    }
80
+		return $stream;
81
+	}
82 82
 }
Please login to merge, or discard this patch.
functions/server_request_method.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
  */
29 29
 function server_request_method(?array $serverParams = null): string
30 30
 {
31
-    $serverParams ??= $_SERVER;
31
+	$serverParams ??= $_SERVER;
32 32
 
33
-    return $serverParams['REQUEST_METHOD'] ?? RequestMethodInterface::METHOD_GET;
33
+	return $serverParams['REQUEST_METHOD'] ?? RequestMethodInterface::METHOD_GET;
34 34
 }
Please login to merge, or discard this patch.
src/ServerRequest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -358,8 +358,8 @@
 block discarded – undo
358 358
         /**
359 359
          * @psalm-suppress MissingClosureParamType
360 360
          */
361
-        array_walk_recursive($files, static function ($file): void {
362
-            if (! ($file instanceof UploadedFileInterface)) {
361
+        array_walk_recursive($files, static function($file): void {
362
+            if (!($file instanceof UploadedFileInterface)) {
363 363
                 throw new InvalidArgumentException('Invalid uploaded file');
364 364
             }
365 365
         });
Please login to merge, or discard this patch.
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -35,354 +35,354 @@
 block discarded – undo
35 35
 class ServerRequest extends Request implements ServerRequestInterface
36 36
 {
37 37
 
38
-    /**
39
-     * The server parameters
40
-     *
41
-     * @var array<array-key, mixed>
42
-     */
43
-    private array $serverParams;
44
-
45
-    /**
46
-     * The request's query parameters
47
-     *
48
-     * @var array<array-key, mixed>
49
-     */
50
-    private array $queryParams;
51
-
52
-    /**
53
-     * The request's cookie parameters
54
-     *
55
-     * @var array<array-key, mixed>
56
-     */
57
-    private array $cookieParams;
58
-
59
-    /**
60
-     * The request's uploaded files
61
-     *
62
-     * @var array<array-key, mixed>
63
-     */
64
-    private array $uploadedFiles = [];
65
-
66
-    /**
67
-     * The request's parsed body
68
-     *
69
-     * @var array<array-key, mixed>|object|null
70
-     */
71
-    private $parsedBody = null;
72
-
73
-    /**
74
-     * The request attributes
75
-     *
76
-     * @var array<array-key, mixed>
77
-     */
78
-    private array $attributes;
79
-
80
-    /**
81
-     * Constructor of the class
82
-     *
83
-     * @param string|null $protocolVersion
84
-     * @param string|null $method
85
-     * @param mixed $uri
86
-     * @param array<string, string|string[]>|null $headers
87
-     * @param StreamInterface|null $body
88
-     *
89
-     * @param array<array-key, mixed> $serverParams
90
-     * @param array<array-key, mixed> $queryParams
91
-     * @param array<array-key, mixed> $cookieParams
92
-     * @param array<array-key, mixed> $uploadedFiles
93
-     * @param array<array-key, mixed>|object|null $parsedBody
94
-     * @param array<array-key, mixed> $attributes
95
-     *
96
-     * @throws InvalidArgumentException
97
-     *         If one of the arguments isn't valid.
98
-     */
99
-    public function __construct(
100
-        ?string $protocolVersion = null,
101
-        ?string $method = null,
102
-        $uri = null,
103
-        ?array $headers = null,
104
-        ?StreamInterface $body = null,
105
-        array $serverParams = [],
106
-        array $queryParams = [],
107
-        array $cookieParams = [],
108
-        array $uploadedFiles = [],
109
-        $parsedBody = null,
110
-        array $attributes = []
111
-    ) {
112
-        parent::__construct($method, $uri, $headers, $body);
113
-
114
-        if (isset($protocolVersion)) {
115
-            $this->setProtocolVersion($protocolVersion);
116
-        }
117
-
118
-        if (!empty($uploadedFiles)) {
119
-            $this->setUploadedFiles($uploadedFiles);
120
-        }
121
-
122
-        if (isset($parsedBody)) {
123
-            $this->setParsedBody($parsedBody);
124
-        }
125
-
126
-        $this->serverParams = $serverParams;
127
-        $this->queryParams = $queryParams;
128
-        $this->cookieParams = $cookieParams;
129
-        $this->attributes = $attributes;
130
-    }
131
-
132
-    /**
133
-     * Gets the server parameters
134
-     *
135
-     * @return array<array-key, mixed>
136
-     */
137
-    public function getServerParams(): array
138
-    {
139
-        return $this->serverParams;
140
-    }
141
-
142
-    /**
143
-     * Gets the request's query parameters
144
-     *
145
-     * @return array<array-key, mixed>
146
-     */
147
-    public function getQueryParams(): array
148
-    {
149
-        return $this->queryParams;
150
-    }
151
-
152
-    /**
153
-     * Creates a new instance of the request with the given query parameters
154
-     *
155
-     * @param array<array-key, mixed> $query
156
-     *
157
-     * @return static
158
-     */
159
-    public function withQueryParams(array $query): ServerRequestInterface
160
-    {
161
-        $clone = clone $this;
162
-        $clone->queryParams = $query;
163
-
164
-        return $clone;
165
-    }
166
-
167
-    /**
168
-     * Gets the request's cookie parameters
169
-     *
170
-     * @return array<array-key, mixed>
171
-     */
172
-    public function getCookieParams(): array
173
-    {
174
-        return $this->cookieParams;
175
-    }
176
-
177
-    /**
178
-     * Creates a new instance of the request with the given cookie parameters
179
-     *
180
-     * @param array<array-key, mixed> $cookies
181
-     *
182
-     * @return static
183
-     */
184
-    public function withCookieParams(array $cookies): ServerRequestInterface
185
-    {
186
-        $clone = clone $this;
187
-        $clone->cookieParams = $cookies;
188
-
189
-        return $clone;
190
-    }
191
-
192
-    /**
193
-     * Gets the request's uploaded files
194
-     *
195
-     * @return array<array-key, mixed>
196
-     */
197
-    public function getUploadedFiles(): array
198
-    {
199
-        return $this->uploadedFiles;
200
-    }
201
-
202
-    /**
203
-     * Creates a new instance of the request with the given uploaded files
204
-     *
205
-     * @param array<array-key, mixed> $uploadedFiles
206
-     *
207
-     * @return static
208
-     *
209
-     * @throws InvalidArgumentException
210
-     *         If one of the files isn't valid.
211
-     */
212
-    public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
213
-    {
214
-        $clone = clone $this;
215
-        $clone->setUploadedFiles($uploadedFiles);
216
-
217
-        return $clone;
218
-    }
219
-
220
-    /**
221
-     * Gets the request's parsed body
222
-     *
223
-     * @return array<array-key, mixed>|object|null
224
-     */
225
-    public function getParsedBody()
226
-    {
227
-        return $this->parsedBody;
228
-    }
229
-
230
-    /**
231
-     * Creates a new instance of the request with the given parsed body
232
-     *
233
-     * @param array<array-key, mixed>|object|null $data
234
-     *
235
-     * @return static
236
-     *
237
-     * @throws InvalidArgumentException
238
-     *         If the data isn't valid.
239
-     */
240
-    public function withParsedBody($data): ServerRequestInterface
241
-    {
242
-        $clone = clone $this;
243
-        $clone->setParsedBody($data);
244
-
245
-        return $clone;
246
-    }
247
-
248
-    /**
249
-     * Gets the request attributes
250
-     *
251
-     * @return array<array-key, mixed>
252
-     */
253
-    public function getAttributes(): array
254
-    {
255
-        return $this->attributes;
256
-    }
257
-
258
-    /**
259
-     * Gets the request's attribute value by the given name
260
-     *
261
-     * Returns the default value if the attribute wasn't found.
262
-     *
263
-     * @param array-key $name
264
-     * @param mixed $default
265
-     *
266
-     * @return mixed
267
-     */
268
-    public function getAttribute($name, $default = null)
269
-    {
270
-        if (!array_key_exists($name, $this->attributes)) {
271
-            return $default;
272
-        }
273
-
274
-        return $this->attributes[$name];
275
-    }
276
-
277
-    /**
278
-     * Creates a new instance of the request with the given attribute
279
-     *
280
-     * @param array-key $name
281
-     * @param mixed $value
282
-     *
283
-     * @return static
284
-     */
285
-    public function withAttribute($name, $value): ServerRequestInterface
286
-    {
287
-        $clone = clone $this;
288
-        $clone->attributes[$name] = $value;
289
-
290
-        return $clone;
291
-    }
292
-
293
-    /**
294
-     * Creates a new instance of the request without an attribute with the given name
295
-     *
296
-     * @param array-key $name
297
-     *
298
-     * @return static
299
-     */
300
-    public function withoutAttribute($name): ServerRequestInterface
301
-    {
302
-        $clone = clone $this;
303
-        unset($clone->attributes[$name]);
304
-
305
-        return $clone;
306
-    }
307
-
308
-    /**
309
-     * Sets the given uploaded files to the request
310
-     *
311
-     * @param array<array-key, mixed> $files
312
-     *
313
-     * @return void
314
-     *
315
-     * @throws InvalidArgumentException
316
-     *         If one of the files isn't valid.
317
-     */
318
-    final protected function setUploadedFiles(array $files): void
319
-    {
320
-        $this->validateUploadedFiles($files);
321
-
322
-        $this->uploadedFiles = $files;
323
-    }
324
-
325
-    /**
326
-     * Sets the given parsed body to the request
327
-     *
328
-     * @param array<array-key, mixed>|object|null $data
329
-     *
330
-     * @return void
331
-     *
332
-     * @throws InvalidArgumentException
333
-     *         If the parsed body isn't valid.
334
-     */
335
-    final protected function setParsedBody($data): void
336
-    {
337
-        $this->validateParsedBody($data);
338
-
339
-        $this->parsedBody = $data;
340
-    }
341
-
342
-    /**
343
-     * Validates the given uploaded files
344
-     *
345
-     * @param array<array-key, mixed> $files
346
-     *
347
-     * @return void
348
-     *
349
-     * @throws InvalidArgumentException
350
-     *         If one of the files isn't valid.
351
-     */
352
-    private function validateUploadedFiles(array $files): void
353
-    {
354
-        if ([] === $files) {
355
-            return;
356
-        }
357
-
358
-        /**
359
-         * @psalm-suppress MissingClosureParamType
360
-         */
361
-        array_walk_recursive($files, static function ($file): void {
362
-            if (! ($file instanceof UploadedFileInterface)) {
363
-                throw new InvalidArgumentException('Invalid uploaded file');
364
-            }
365
-        });
366
-    }
367
-
368
-    /**
369
-     * Validates the given parsed body
370
-     *
371
-     * @param mixed $data
372
-     *
373
-     * @return void
374
-     *
375
-     * @throws InvalidArgumentException
376
-     *         If the parsed body isn't valid.
377
-     */
378
-    private function validateParsedBody($data): void
379
-    {
380
-        if (null === $data) {
381
-            return;
382
-        }
383
-
384
-        if (!is_array($data) && !is_object($data)) {
385
-            throw new InvalidArgumentException('Invalid parsed body');
386
-        }
387
-    }
38
+	/**
39
+	 * The server parameters
40
+	 *
41
+	 * @var array<array-key, mixed>
42
+	 */
43
+	private array $serverParams;
44
+
45
+	/**
46
+	 * The request's query parameters
47
+	 *
48
+	 * @var array<array-key, mixed>
49
+	 */
50
+	private array $queryParams;
51
+
52
+	/**
53
+	 * The request's cookie parameters
54
+	 *
55
+	 * @var array<array-key, mixed>
56
+	 */
57
+	private array $cookieParams;
58
+
59
+	/**
60
+	 * The request's uploaded files
61
+	 *
62
+	 * @var array<array-key, mixed>
63
+	 */
64
+	private array $uploadedFiles = [];
65
+
66
+	/**
67
+	 * The request's parsed body
68
+	 *
69
+	 * @var array<array-key, mixed>|object|null
70
+	 */
71
+	private $parsedBody = null;
72
+
73
+	/**
74
+	 * The request attributes
75
+	 *
76
+	 * @var array<array-key, mixed>
77
+	 */
78
+	private array $attributes;
79
+
80
+	/**
81
+	 * Constructor of the class
82
+	 *
83
+	 * @param string|null $protocolVersion
84
+	 * @param string|null $method
85
+	 * @param mixed $uri
86
+	 * @param array<string, string|string[]>|null $headers
87
+	 * @param StreamInterface|null $body
88
+	 *
89
+	 * @param array<array-key, mixed> $serverParams
90
+	 * @param array<array-key, mixed> $queryParams
91
+	 * @param array<array-key, mixed> $cookieParams
92
+	 * @param array<array-key, mixed> $uploadedFiles
93
+	 * @param array<array-key, mixed>|object|null $parsedBody
94
+	 * @param array<array-key, mixed> $attributes
95
+	 *
96
+	 * @throws InvalidArgumentException
97
+	 *         If one of the arguments isn't valid.
98
+	 */
99
+	public function __construct(
100
+		?string $protocolVersion = null,
101
+		?string $method = null,
102
+		$uri = null,
103
+		?array $headers = null,
104
+		?StreamInterface $body = null,
105
+		array $serverParams = [],
106
+		array $queryParams = [],
107
+		array $cookieParams = [],
108
+		array $uploadedFiles = [],
109
+		$parsedBody = null,
110
+		array $attributes = []
111
+	) {
112
+		parent::__construct($method, $uri, $headers, $body);
113
+
114
+		if (isset($protocolVersion)) {
115
+			$this->setProtocolVersion($protocolVersion);
116
+		}
117
+
118
+		if (!empty($uploadedFiles)) {
119
+			$this->setUploadedFiles($uploadedFiles);
120
+		}
121
+
122
+		if (isset($parsedBody)) {
123
+			$this->setParsedBody($parsedBody);
124
+		}
125
+
126
+		$this->serverParams = $serverParams;
127
+		$this->queryParams = $queryParams;
128
+		$this->cookieParams = $cookieParams;
129
+		$this->attributes = $attributes;
130
+	}
131
+
132
+	/**
133
+	 * Gets the server parameters
134
+	 *
135
+	 * @return array<array-key, mixed>
136
+	 */
137
+	public function getServerParams(): array
138
+	{
139
+		return $this->serverParams;
140
+	}
141
+
142
+	/**
143
+	 * Gets the request's query parameters
144
+	 *
145
+	 * @return array<array-key, mixed>
146
+	 */
147
+	public function getQueryParams(): array
148
+	{
149
+		return $this->queryParams;
150
+	}
151
+
152
+	/**
153
+	 * Creates a new instance of the request with the given query parameters
154
+	 *
155
+	 * @param array<array-key, mixed> $query
156
+	 *
157
+	 * @return static
158
+	 */
159
+	public function withQueryParams(array $query): ServerRequestInterface
160
+	{
161
+		$clone = clone $this;
162
+		$clone->queryParams = $query;
163
+
164
+		return $clone;
165
+	}
166
+
167
+	/**
168
+	 * Gets the request's cookie parameters
169
+	 *
170
+	 * @return array<array-key, mixed>
171
+	 */
172
+	public function getCookieParams(): array
173
+	{
174
+		return $this->cookieParams;
175
+	}
176
+
177
+	/**
178
+	 * Creates a new instance of the request with the given cookie parameters
179
+	 *
180
+	 * @param array<array-key, mixed> $cookies
181
+	 *
182
+	 * @return static
183
+	 */
184
+	public function withCookieParams(array $cookies): ServerRequestInterface
185
+	{
186
+		$clone = clone $this;
187
+		$clone->cookieParams = $cookies;
188
+
189
+		return $clone;
190
+	}
191
+
192
+	/**
193
+	 * Gets the request's uploaded files
194
+	 *
195
+	 * @return array<array-key, mixed>
196
+	 */
197
+	public function getUploadedFiles(): array
198
+	{
199
+		return $this->uploadedFiles;
200
+	}
201
+
202
+	/**
203
+	 * Creates a new instance of the request with the given uploaded files
204
+	 *
205
+	 * @param array<array-key, mixed> $uploadedFiles
206
+	 *
207
+	 * @return static
208
+	 *
209
+	 * @throws InvalidArgumentException
210
+	 *         If one of the files isn't valid.
211
+	 */
212
+	public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
213
+	{
214
+		$clone = clone $this;
215
+		$clone->setUploadedFiles($uploadedFiles);
216
+
217
+		return $clone;
218
+	}
219
+
220
+	/**
221
+	 * Gets the request's parsed body
222
+	 *
223
+	 * @return array<array-key, mixed>|object|null
224
+	 */
225
+	public function getParsedBody()
226
+	{
227
+		return $this->parsedBody;
228
+	}
229
+
230
+	/**
231
+	 * Creates a new instance of the request with the given parsed body
232
+	 *
233
+	 * @param array<array-key, mixed>|object|null $data
234
+	 *
235
+	 * @return static
236
+	 *
237
+	 * @throws InvalidArgumentException
238
+	 *         If the data isn't valid.
239
+	 */
240
+	public function withParsedBody($data): ServerRequestInterface
241
+	{
242
+		$clone = clone $this;
243
+		$clone->setParsedBody($data);
244
+
245
+		return $clone;
246
+	}
247
+
248
+	/**
249
+	 * Gets the request attributes
250
+	 *
251
+	 * @return array<array-key, mixed>
252
+	 */
253
+	public function getAttributes(): array
254
+	{
255
+		return $this->attributes;
256
+	}
257
+
258
+	/**
259
+	 * Gets the request's attribute value by the given name
260
+	 *
261
+	 * Returns the default value if the attribute wasn't found.
262
+	 *
263
+	 * @param array-key $name
264
+	 * @param mixed $default
265
+	 *
266
+	 * @return mixed
267
+	 */
268
+	public function getAttribute($name, $default = null)
269
+	{
270
+		if (!array_key_exists($name, $this->attributes)) {
271
+			return $default;
272
+		}
273
+
274
+		return $this->attributes[$name];
275
+	}
276
+
277
+	/**
278
+	 * Creates a new instance of the request with the given attribute
279
+	 *
280
+	 * @param array-key $name
281
+	 * @param mixed $value
282
+	 *
283
+	 * @return static
284
+	 */
285
+	public function withAttribute($name, $value): ServerRequestInterface
286
+	{
287
+		$clone = clone $this;
288
+		$clone->attributes[$name] = $value;
289
+
290
+		return $clone;
291
+	}
292
+
293
+	/**
294
+	 * Creates a new instance of the request without an attribute with the given name
295
+	 *
296
+	 * @param array-key $name
297
+	 *
298
+	 * @return static
299
+	 */
300
+	public function withoutAttribute($name): ServerRequestInterface
301
+	{
302
+		$clone = clone $this;
303
+		unset($clone->attributes[$name]);
304
+
305
+		return $clone;
306
+	}
307
+
308
+	/**
309
+	 * Sets the given uploaded files to the request
310
+	 *
311
+	 * @param array<array-key, mixed> $files
312
+	 *
313
+	 * @return void
314
+	 *
315
+	 * @throws InvalidArgumentException
316
+	 *         If one of the files isn't valid.
317
+	 */
318
+	final protected function setUploadedFiles(array $files): void
319
+	{
320
+		$this->validateUploadedFiles($files);
321
+
322
+		$this->uploadedFiles = $files;
323
+	}
324
+
325
+	/**
326
+	 * Sets the given parsed body to the request
327
+	 *
328
+	 * @param array<array-key, mixed>|object|null $data
329
+	 *
330
+	 * @return void
331
+	 *
332
+	 * @throws InvalidArgumentException
333
+	 *         If the parsed body isn't valid.
334
+	 */
335
+	final protected function setParsedBody($data): void
336
+	{
337
+		$this->validateParsedBody($data);
338
+
339
+		$this->parsedBody = $data;
340
+	}
341
+
342
+	/**
343
+	 * Validates the given uploaded files
344
+	 *
345
+	 * @param array<array-key, mixed> $files
346
+	 *
347
+	 * @return void
348
+	 *
349
+	 * @throws InvalidArgumentException
350
+	 *         If one of the files isn't valid.
351
+	 */
352
+	private function validateUploadedFiles(array $files): void
353
+	{
354
+		if ([] === $files) {
355
+			return;
356
+		}
357
+
358
+		/**
359
+		 * @psalm-suppress MissingClosureParamType
360
+		 */
361
+		array_walk_recursive($files, static function ($file): void {
362
+			if (! ($file instanceof UploadedFileInterface)) {
363
+				throw new InvalidArgumentException('Invalid uploaded file');
364
+			}
365
+		});
366
+	}
367
+
368
+	/**
369
+	 * Validates the given parsed body
370
+	 *
371
+	 * @param mixed $data
372
+	 *
373
+	 * @return void
374
+	 *
375
+	 * @throws InvalidArgumentException
376
+	 *         If the parsed body isn't valid.
377
+	 */
378
+	private function validateParsedBody($data): void
379
+	{
380
+		if (null === $data) {
381
+			return;
382
+		}
383
+
384
+		if (!is_array($data) && !is_object($data)) {
385
+			throw new InvalidArgumentException('Invalid parsed body');
386
+		}
387
+	}
388 388
 }
Please login to merge, or discard this patch.