PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
← All changes | vendor_prefixed/guzzlehttp/psr7/src/Response.php +32 -19 18.2 → trunk View file →
@@ -1,6 +1,7 @@
1 1 <?php
2 2
3 +declare (strict_types=1);
3 4 namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
4 5
5 6 use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
6 7 use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
@@ -9,66 +10,78 @@
9 10 */
10 11 class Response implements \YoastSEO_Vendor\Psr\Http\Message\ResponseInterface
11 12 {
12 13 use MessageTrait;
13 - /** @var array Map of standard HTTP status code/reason phrases */
14 - private static $phrases = [100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 511 => 'Network Authentication Required'];
14 + /** Map of standard HTTP status code/reason phrases */
15 + private const PHRASES = [100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 510 => 'Not Extended', 511 => 'Network Authentication Required'];
15 16 /** @var string */
16 - private $reasonPhrase = '';
17 + private $reasonPhrase;
17 18 /** @var int */
18 - private $statusCode = 200;
19 + private $statusCode;
19 20 /**
20 21 * @param int $status Status code
21 - * @param array $headers Response headers
22 + * @param (string|string[])[] $headers Response headers
22 23 * @param string|resource|StreamInterface|null $body Response body
23 24 * @param string $version Protocol version
24 25 * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
25 26 */
26 - public function __construct($status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null)
27 + public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', ?string $reason = null)
27 28 {
28 - $this->assertStatusCodeIsInteger($status);
29 - $status = (int) $status;
30 29 $this->assertStatusCodeRange($status);
30 + $this->assertProtocolVersion($version);
31 31 $this->statusCode = $status;
32 32 if ($body !== '' && $body !== null) {
33 33 $this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
34 34 }
35 35 $this->setHeaders($headers);
36 - if ($reason == '' && isset(self::$phrases[$this->statusCode])) {
37 - $this->reasonPhrase = self::$phrases[$this->statusCode];
36 + if ($reason == '' && isset(self::PHRASES[$this->statusCode])) {
37 + $reasonPhrase = self::PHRASES[$this->statusCode];
38 38 } else {
39 - $this->reasonPhrase = (string) $reason;
39 + $reasonPhrase = (string) $reason;
40 40 }
41 + $this->assertNoLineSeparators($reasonPhrase, 'Reason phrase');
42 + $this->reasonPhrase = $reasonPhrase;
41 43 $this->protocol = $version;
42 44 }
43 - public function getStatusCode()
45 + public function getStatusCode() : int
44 46 {
45 47 return $this->statusCode;
46 48 }
47 - public function getReasonPhrase()
49 + public function getReasonPhrase() : string
48 50 {
49 51 return $this->reasonPhrase;
50 52 }
51 - public function withStatus($code, $reasonPhrase = '')
53 + public function withStatus($code, $reasonPhrase = '') : \YoastSEO_Vendor\Psr\Http\Message\ResponseInterface
52 54 {
55 + if (!\is_int($code) && \filter_var($code, \FILTER_VALIDATE_INT) !== \false) {
56 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to ResponseInterface::withStatus() is deprecated; guzzlehttp/psr7 3.0 requires int for $code.', \get_debug_type($code));
57 + }
58 + if (!\is_string($reasonPhrase)) {
59 + \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/psr7', '2.11', 'Passing %s to ResponseInterface::withStatus() is deprecated; guzzlehttp/psr7 3.0 requires string for $reasonPhrase.', \get_debug_type($reasonPhrase));
60 + }
53 61 $this->assertStatusCodeIsInteger($code);
54 62 $code = (int) $code;
55 63 $this->assertStatusCodeRange($code);
56 64 $new = clone $this;
57 65 $new->statusCode = $code;
58 - if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
59 - $reasonPhrase = self::$phrases[$new->statusCode];
66 + if ($reasonPhrase == '' && isset(self::PHRASES[$new->statusCode])) {
67 + $reasonPhrase = self::PHRASES[$new->statusCode];
60 68 }
61 - $new->reasonPhrase = (string) $reasonPhrase;
69 + $reasonPhrase = (string) $reasonPhrase;
70 + $this->assertNoLineSeparators($reasonPhrase, 'Reason phrase');
71 + $new->reasonPhrase = $reasonPhrase;
62 72 return $new;
63 73 }
64 - private function assertStatusCodeIsInteger($statusCode)
74 + /**
75 + * @param mixed $statusCode
76 + */
77 + private function assertStatusCodeIsInteger($statusCode) : void
65 78 {
66 79 if (\filter_var($statusCode, \FILTER_VALIDATE_INT) === \false) {
67 80 throw new \InvalidArgumentException('Status code must be an integer value.');
68 81 }
69 82 }
70 - private function assertStatusCodeRange($statusCode)
83 + private function assertStatusCodeRange(int $statusCode) : void
71 84 {
72 85 if ($statusCode < 100 || $statusCode >= 600) {
73 86 throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
74 87 }