PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/sdk/google/guzzlehttp/psr7/src/Message.php +36 -36 1.0.1 → 1.4.2 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2
3 3 declare (strict_types=1);
4 -namespace Dudlewebs\WPMCS\GuzzleHttp\Psr7;
4 +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7;
5 5
6 -use Dudlewebs\WPMCS\Psr\Http\Message\MessageInterface;
7 -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface;
8 -use Dudlewebs\WPMCS\Psr\Http\Message\ResponseInterface;
6 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\MessageInterface;
7 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface;
8 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\ResponseInterface;
9 9 final class Message
10 10 {
11 11 /**
12 12 * Returns the string representation of an HTTP message.
@@ -12,12 +12,12 @@
12 12 * Returns the string representation of an HTTP message.
13 13 *
14 14 * @param MessageInterface $message Message to convert to a string.
15 15 */
16 - public static function toString(MessageInterface $message): string
16 + public static function toString(MessageInterface $message) : string
17 17 {
18 18 if ($message instanceof RequestInterface) {
19 - $msg = trim($message->getMethod() . ' ' . $message->getRequestTarget()) . ' HTTP/' . $message->getProtocolVersion();
19 + $msg = \trim($message->getMethod() . ' ' . $message->getRequestTarget()) . ' HTTP/' . $message->getProtocolVersion();
20 20 if (!$message->hasHeader('host')) {
21 21 $msg .= "\r\nHost: " . $message->getUri()->getHost();
22 22 }
23 23 } elseif ($message instanceof ResponseInterface) {
@@ -25,14 +25,14 @@
25 25 } else {
26 26 throw new \InvalidArgumentException('Unknown message type');
27 27 }
28 28 foreach ($message->getHeaders() as $name => $values) {
29 - if (is_string($name) && strtolower($name) === 'set-cookie') {
29 + if (\is_string($name) && \strtolower($name) === 'set-cookie') {
30 30 foreach ($values as $value) {
31 31 $msg .= "\r\n{$name}: " . $value;
32 32 }
33 33 } else {
34 - $msg .= "\r\n{$name}: " . implode(', ', $values);
34 + $msg .= "\r\n{$name}: " . \implode(', ', $values);
35 35 }
36 36 }
37 37 return "{$msg}\r\n\r\n" . $message->getBody();
38 38 }
@@ -43,9 +43,9 @@
43 43 *
44 44 * @param MessageInterface $message The message to get the body summary
45 45 * @param int $truncateAt The maximum allowed size of the summary
46 46 */
47 - public static function bodySummary(MessageInterface $message, int $truncateAt = 120): ?string
47 + public static function bodySummary(MessageInterface $message, int $truncateAt = 120) : ?string
48 48 {
49 49 $body = $message->getBody();
50 50 if (!$body->isSeekable() || !$body->isReadable()) {
51 51 return null;
@@ -61,9 +61,9 @@
61 61 $summary .= ' (truncated...)';
62 62 }
63 63 // Matches any printable character, including unicode characters:
64 64 // letters, marks, numbers, punctuation, spacing, and separators.
65 - if (preg_match('/[^\pL\pM\pN\pP\pS\pZ\n\r\t]/u', $summary) !== 0) {
65 + if (\preg_match('/[^\\pL\\pM\\pN\\pP\\pS\\pZ\\n\\r\\t]/u', $summary) !== 0) {
66 66 return null;
67 67 }
68 68 return $summary;
69 69 }
@@ -76,9 +76,9 @@
76 76 * @param MessageInterface $message Message to rewind
77 77 *
78 78 * @throws \RuntimeException
79 79 */
80 - public static function rewindBody(MessageInterface $message): void
80 + public static function rewindBody(MessageInterface $message) : void
81 81 {
82 82 $body = $message->getBody();
83 83 if ($body->tell()) {
84 84 $body->rewind();
@@ -92,36 +92,36 @@
92 92 * array values, and a "body" key containing the body of the message.
93 93 *
94 94 * @param string $message HTTP request or response to parse.
95 95 */
96 - public static function parseMessage(string $message): array
96 + public static function parseMessage(string $message) : array
97 97 {
98 98 if (!$message) {
99 99 throw new \InvalidArgumentException('Invalid message');
100 100 }
101 - $message = ltrim($message, "\r\n");
102 - $messageParts = preg_split("/\r?\n\r?\n/", $message, 2);
103 - if ($messageParts === \false || count($messageParts) !== 2) {
101 + $message = \ltrim($message, "\r\n");
102 + $messageParts = \preg_split("/\r?\n\r?\n/", $message, 2);
103 + if ($messageParts === \false || \count($messageParts) !== 2) {
104 104 throw new \InvalidArgumentException('Invalid message: Missing header delimiter');
105 105 }
106 106 [$rawHeaders, $body] = $messageParts;
107 107 $rawHeaders .= "\r\n";
108 108 // Put back the delimiter we split previously
109 - $headerParts = preg_split("/\r?\n/", $rawHeaders, 2);
110 - if ($headerParts === \false || count($headerParts) !== 2) {
109 + $headerParts = \preg_split("/\r?\n/", $rawHeaders, 2);
110 + if ($headerParts === \false || \count($headerParts) !== 2) {
111 111 throw new \InvalidArgumentException('Invalid message: Missing status line');
112 112 }
113 113 [$startLine, $rawHeaders] = $headerParts;
114 - if (preg_match("/(?:^HTTP\\/|^[A-Z]+ \\S+ HTTP\\/)(\\d+(?:\\.\\d+)?)/i", $startLine, $matches) && $matches[1] === '1.0') {
114 + if (\preg_match("/(?:^HTTP\\/|^[A-Z]+ \\S+ HTTP\\/)(\\d+(?:\\.\\d+)?)/i", $startLine, $matches) && $matches[1] === '1.0') {
115 115 // Header folding is deprecated for HTTP/1.1, but allowed in HTTP/1.0
116 - $rawHeaders = preg_replace(Rfc7230::HEADER_FOLD_REGEX, ' ', $rawHeaders);
116 + $rawHeaders = \preg_replace(Rfc7230::HEADER_FOLD_REGEX, ' ', $rawHeaders);
117 117 }
118 118 /** @var array[] $headerLines */
119 - $count = preg_match_all(Rfc7230::HEADER_REGEX, $rawHeaders, $headerLines, \PREG_SET_ORDER);
119 + $count = \preg_match_all(Rfc7230::HEADER_REGEX, $rawHeaders, $headerLines, \PREG_SET_ORDER);
120 120 // If these aren't the same, then one line didn't match and there's an invalid header.
121 - if ($count !== substr_count($rawHeaders, "\n")) {
121 + if ($count !== \substr_count($rawHeaders, "\n")) {
122 122 // Folding is deprecated, see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4
123 - if (preg_match(Rfc7230::HEADER_FOLD_REGEX, $rawHeaders)) {
123 + if (\preg_match(Rfc7230::HEADER_FOLD_REGEX, $rawHeaders)) {
124 124 throw new \InvalidArgumentException('Invalid header syntax: Obsolete line folding');
125 125 }
126 126 throw new \InvalidArgumentException('Invalid header syntax');
127 127 }
@@ -136,22 +136,22 @@
136 136 *
137 137 * @param string $path Path from the start-line
138 138 * @param array $headers Array of headers (each value an array).
139 139 */
140 - public static function parseRequestUri(string $path, array $headers): string
140 + public static function parseRequestUri(string $path, array $headers) : string
141 141 {
142 - $hostKey = array_filter(array_keys($headers), function ($k) {
142 + $hostKey = \array_filter(\array_keys($headers), function ($k) {
143 143 // Numeric array keys are converted to int by PHP.
144 144 $k = (string) $k;
145 - return strtolower($k) === 'host';
145 + return \strtolower($k) === 'host';
146 146 });
147 147 // If no host is found, then a full URI cannot be constructed.
148 148 if (!$hostKey) {
149 149 return $path;
150 150 }
151 - $host = $headers[reset($hostKey)][0];
152 - $scheme = substr($host, -4) === ':443' ? 'https' : 'http';
153 - return $scheme . '://' . $host . '/' . ltrim($path, '/');
151 + $host = $headers[\reset($hostKey)][0];
152 + $scheme = \substr($host, -4) === ':443' ? 'https' : 'http';
153 + return $scheme . '://' . $host . '/' . \ltrim($path, '/');
154 154 }
155 155 /**
156 156 * Parses a request message string into a request object.
157 157 *
@@ -156,17 +156,17 @@
156 156 * Parses a request message string into a request object.
157 157 *
158 158 * @param string $message Request message string.
159 159 */
160 - public static function parseRequest(string $message): RequestInterface
160 + public static function parseRequest(string $message) : RequestInterface
161 161 {
162 162 $data = self::parseMessage($message);
163 163 $matches = [];
164 - if (!preg_match('/^[\S]+\s+([a-zA-Z]+:\/\/|\/).*/', $data['start-line'], $matches)) {
164 + if (!\preg_match('/^[\\S]+\\s+([a-zA-Z]+:\\/\\/|\\/).*/', $data['start-line'], $matches)) {
165 165 throw new \InvalidArgumentException('Invalid request string');
166 166 }
167 - $parts = explode(' ', $data['start-line'], 3);
168 - $version = isset($parts[2]) ? explode('/', $parts[2])[1] : '1.1';
167 + $parts = \explode(' ', $data['start-line'], 3);
168 + $version = isset($parts[2]) ? \explode('/', $parts[2])[1] : '1.1';
169 169 $request = new Request($parts[0], $matches[1] === '/' ? self::parseRequestUri($parts[1], $data['headers']) : $parts[1], $data['headers'], $data['body'], $version);
170 170 return $matches[1] === '/' ? $request : $request->withRequestTarget($parts[1]);
171 171 }
172 172 /**
@@ -173,17 +173,17 @@
173 173 * Parses a response message string into a response object.
174 174 *
175 175 * @param string $message Response message string.
176 176 */
177 - public static function parseResponse(string $message): ResponseInterface
177 + public static function parseResponse(string $message) : ResponseInterface
178 178 {
179 179 $data = self::parseMessage($message);
180 180 // According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2
181 181 // the space between status-code and reason-phrase is required. But
182 182 // browsers accept responses without space and reason as well.
183 - if (!preg_match('/^HTTP\/.* [0-9]{3}( .*|$)/', $data['start-line'])) {
183 + if (!\preg_match('/^HTTP\\/.* [0-9]{3}( .*|$)/', $data['start-line'])) {
184 184 throw new \InvalidArgumentException('Invalid response string: ' . $data['start-line']);
185 185 }
186 - $parts = explode(' ', $data['start-line'], 3);
187 - return new Response((int) $parts[1], $data['headers'], $data['body'], explode('/', $parts[0])[1], $parts[2] ?? null);
186 + $parts = \explode(' ', $data['start-line'], 3);
187 + return new Response((int) $parts[1], $data['headers'], $data['body'], \explode('/', $parts[0])[1], $parts[2] ?? null);
188 188 }
189 189 }