Skip to content

Commit 2964cc5

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Fix quotes in exception messages Fix quotes in exception messages Fix quotes in exception messages
2 parents d7973ff + d2d1c0b commit 2964cc5

10 files changed

+28
-28
lines changed

CachingHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
114114
if ($responses instanceof ResponseInterface) {
115115
$responses = [$responses];
116116
} elseif (!is_iterable($responses)) {
117-
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of ResponseInterface objects, %s given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
117+
throw new \TypeError(sprintf('"%s()" expects parameter 1 to be an iterable of ResponseInterface objects, "%s" given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
118118
}
119119

120120
$mockResponses = [];

CurlHttpClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ public function request(string $method, string $url, array $options = []): Respo
156156
if (\is_array($options['auth_ntlm'])) {
157157
$count = \count($options['auth_ntlm']);
158158
if ($count <= 0 || $count > 2) {
159-
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must contain 1 or 2 elements, %s given.', $count));
159+
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must contain 1 or 2 elements, %d given.', $count));
160160
}
161161

162162
$options['auth_ntlm'] = implode(':', $options['auth_ntlm']);
163163
}
164164

165165
if (!\is_string($options['auth_ntlm'])) {
166-
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be a string or an array, %s given.', \gettype($options['auth_ntlm'])));
166+
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be a string or an array, "%s" given.', \gettype($options['auth_ntlm'])));
167167
}
168168

169169
$curlopts[CURLOPT_USERPWD] = $options['auth_ntlm'];
@@ -319,7 +319,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
319319
if ($responses instanceof CurlResponse) {
320320
$responses = [$responses];
321321
} elseif (!is_iterable($responses)) {
322-
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of CurlResponse objects, %s given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
322+
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of CurlResponse objects, "%s" given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
323323
}
324324

325325
$active = 0;
@@ -439,7 +439,7 @@ private static function readRequestBody(int $length, \Closure $body, string &$bu
439439
{
440440
if (!$eof && \strlen($buffer) < $length) {
441441
if (!\is_string($data = $body($length))) {
442-
throw new TransportException(sprintf('The return value of the "body" option callback must be a string, %s returned.', \gettype($data)));
442+
throw new TransportException(sprintf('The return value of the "body" option callback must be a string, "%s" returned.', \gettype($data)));
443443
}
444444

445445
$buffer .= $data;

HttpClientTrait.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
4848
$options['buffer'] = static function (array $headers) use ($buffer) {
4949
if (!\is_bool($buffer = $buffer($headers))) {
5050
if (!\is_array($bufferInfo = @stream_get_meta_data($buffer))) {
51-
throw new \LogicException(sprintf('The closure passed as option "buffer" must return bool or stream resource, got %s.', \is_resource($buffer) ? get_resource_type($buffer).' resource' : \gettype($buffer)));
51+
throw new \LogicException(sprintf('The closure passed as option "buffer" must return bool or stream resource, got "%s".', \is_resource($buffer) ? get_resource_type($buffer).' resource' : \gettype($buffer)));
5252
}
5353

5454
if (false === strpbrk($bufferInfo['mode'], 'acew+')) {
@@ -60,7 +60,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
6060
};
6161
} elseif (!\is_bool($buffer)) {
6262
if (!\is_array($bufferInfo = @stream_get_meta_data($buffer))) {
63-
throw new InvalidArgumentException(sprintf('Option "buffer" must be bool, stream resource or Closure, %s given.', \is_resource($buffer) ? get_resource_type($buffer).' resource' : \gettype($buffer)));
63+
throw new InvalidArgumentException(sprintf('Option "buffer" must be bool, stream resource or Closure, "%s" given.', \is_resource($buffer) ? get_resource_type($buffer).' resource' : \gettype($buffer)));
6464
}
6565

6666
if (false === strpbrk($bufferInfo['mode'], 'acew+')) {
@@ -94,24 +94,24 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
9494

9595
// Validate on_progress
9696
if (!\is_callable($onProgress = $options['on_progress'] ?? 'var_dump')) {
97-
throw new InvalidArgumentException(sprintf('Option "on_progress" must be callable, %s given.', \is_object($onProgress) ? \get_class($onProgress) : \gettype($onProgress)));
97+
throw new InvalidArgumentException(sprintf('Option "on_progress" must be callable, "%s" given.', \is_object($onProgress) ? \get_class($onProgress) : \gettype($onProgress)));
9898
}
9999

100100
if (\is_array($options['auth_basic'] ?? null)) {
101101
$count = \count($options['auth_basic']);
102102
if ($count <= 0 || $count > 2) {
103-
throw new InvalidArgumentException(sprintf('Option "auth_basic" must contain 1 or 2 elements, %s given.', $count));
103+
throw new InvalidArgumentException(sprintf('Option "auth_basic" must contain 1 or 2 elements, "%s" given.', $count));
104104
}
105105

106106
$options['auth_basic'] = implode(':', $options['auth_basic']);
107107
}
108108

109109
if (!\is_string($options['auth_basic'] ?? '')) {
110-
throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, %s given.', \gettype($options['auth_basic'])));
110+
throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, "%s" given.', \gettype($options['auth_basic'])));
111111
}
112112

113113
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
114-
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : \gettype($options['auth_bearer'])));
114+
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : '"'.\gettype($options['auth_bearer']).'"'));
115115
}
116116

117117
if (isset($options['auth_basic'], $options['auth_bearer'])) {
@@ -206,10 +206,10 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
206206
}
207207

208208
if ('auth_ntlm' === $name) {
209-
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by %s, try using CurlHttpClient instead.', __CLASS__));
209+
throw new InvalidArgumentException(sprintf('Option "auth_ntlm" is not supported by "%s", try using CurlHttpClient instead.', __CLASS__));
210210
}
211211

212-
throw new InvalidArgumentException(sprintf('Unsupported option "%s" passed to %s, did you mean "%s"?', $name, __CLASS__, implode('", "', $alternatives ?: array_keys($defaultOptions))));
212+
throw new InvalidArgumentException(sprintf('Unsupported option "%s" passed to "%s", did you mean "%s"?', $name, __CLASS__, implode('", "', $alternatives ?: array_keys($defaultOptions))));
213213
}
214214

215215
return $options;
@@ -231,13 +231,13 @@ private static function normalizeHeaders(array $headers): array
231231

232232
if (\is_int($name)) {
233233
if (!\is_string($values)) {
234-
throw new InvalidArgumentException(sprintf('Invalid value for header "%s": expected string, %s given.', $name, \gettype($values)));
234+
throw new InvalidArgumentException(sprintf('Invalid value for header "%s": expected string, "%s" given.', $name, \gettype($values)));
235235
}
236236
[$name, $values] = explode(':', $values, 2);
237237
$values = [ltrim($values)];
238238
} elseif (!is_iterable($values)) {
239239
if (\is_object($values)) {
240-
throw new InvalidArgumentException(sprintf('Invalid value for header "%s": expected string, %s given.', $name, \get_class($values)));
240+
throw new InvalidArgumentException(sprintf('Invalid value for header "%s": expected string, "%s" given.', $name, \get_class($values)));
241241
}
242242

243243
$values = (array) $values;
@@ -299,7 +299,7 @@ private static function normalizeBody($body)
299299
}
300300

301301
if (!\is_string($body) && !\is_array(@stream_get_meta_data($body))) {
302-
throw new InvalidArgumentException(sprintf('Option "body" must be string, stream resource, iterable or callable, %s given.', \is_resource($body) ? get_resource_type($body) : \gettype($body)));
302+
throw new InvalidArgumentException(sprintf('Option "body" must be string, stream resource, iterable or callable, "%s" given.', \is_resource($body) ? get_resource_type($body) : \gettype($body)));
303303
}
304304

305305
return $body;
@@ -325,7 +325,7 @@ private static function normalizePeerFingerprint($fingerprint): array
325325
$fingerprint[$algo] = 'pin-sha256' === $algo ? (array) $hash : str_replace(':', '', $hash);
326326
}
327327
} else {
328-
throw new InvalidArgumentException(sprintf('Option "peer_fingerprint" must be string or array, %s given.', \gettype($fingerprint)));
328+
throw new InvalidArgumentException(sprintf('Option "peer_fingerprint" must be string or array, "%s" given.', \gettype($fingerprint)));
329329
}
330330

331331
return $fingerprint;

HttplugClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function createStream($body = null): StreamInterface
184184
} elseif (\is_resource($body)) {
185185
$stream = $this->streamFactory->createStreamFromResource($body);
186186
} else {
187-
throw new \InvalidArgumentException(sprintf('%s() expects string, resource or StreamInterface, %s given.', __METHOD__, \gettype($body)));
187+
throw new \InvalidArgumentException(sprintf('"%s()" expects string, resource or StreamInterface, "%s" given.', __METHOD__, \gettype($body)));
188188
}
189189

190190
if ($stream->isSeekable()) {

MockHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
7979
if ($responses instanceof ResponseInterface) {
8080
$responses = [$responses];
8181
} elseif (!is_iterable($responses)) {
82-
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of MockResponse objects, %s given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
82+
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of MockResponse objects, "%s" given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
8383
}
8484

8585
return new ResponseStream(MockResponse::stream($responses, $timeout));

NativeHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
238238
if ($responses instanceof NativeResponse) {
239239
$responses = [$responses];
240240
} elseif (!is_iterable($responses)) {
241-
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of NativeResponse objects, %s given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
241+
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of NativeResponse objects, "%s" given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
242242
}
243243

244244
return new ResponseStream(NativeResponse::stream($responses, $timeout));
@@ -258,7 +258,7 @@ private static function getBodyAsString($body): string
258258

259259
while ('' !== $data = $body(self::$CHUNK_SIZE)) {
260260
if (!\is_string($data)) {
261-
throw new TransportException(sprintf('Return value of the "body" option callback must be string, %s returned.', \gettype($data)));
261+
throw new TransportException(sprintf('Return value of the "body" option callback must be string, "%s" returned.', \gettype($data)));
262262
}
263263

264264
$result .= $data;

Response/MockResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private static function writeRequest(self $response, array $options, ResponseInt
228228
} elseif ($body instanceof \Closure) {
229229
while ('' !== $data = $body(16372)) {
230230
if (!\is_string($data)) {
231-
throw new TransportException(sprintf('Return value of the "body" option callback must be string, %s returned.', \gettype($data)));
231+
throw new TransportException(sprintf('Return value of the "body" option callback must be string, "%s" returned.', \gettype($data)));
232232
}
233233

234234
// "notify" upload progress
@@ -295,7 +295,7 @@ private static function readResponse(self $response, array $options, ResponseInt
295295
$onProgress($offset, $dlSize, $response->info);
296296

297297
if ($dlSize && $offset !== $dlSize) {
298-
throw new TransportException(sprintf('Transfer closed with %s bytes remaining to read.', $dlSize - $offset));
298+
throw new TransportException(sprintf('Transfer closed with %d bytes remaining to read.', $dlSize - $offset));
299299
}
300300
}
301301
}

Response/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function toArray(bool $throw = true): array
161161
}
162162

163163
if (!\is_array($content)) {
164-
throw new JsonException(sprintf('JSON content was expected to decode to an array, %s returned for "%s".', \gettype($content), $this->getInfo('url')));
164+
throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned for "%s".', \gettype($content), $this->getInfo('url')));
165165
}
166166

167167
if (null !== $this->content) {

Tests/HttpClientTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function testAuthBearerOption()
179179
public function testInvalidAuthBearerOption()
180180
{
181181
$this->expectException('Symfony\Component\HttpClient\Exception\InvalidArgumentException');
182-
$this->expectExceptionMessage('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, object given.');
182+
$this->expectExceptionMessage('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, "object" given.');
183183
self::prepareRequest('POST', 'http://example.com', ['auth_bearer' => new \stdClass()], HttpClientInterface::OPTIONS_DEFAULTS);
184184
}
185185

@@ -249,7 +249,7 @@ public function testNormalizePeerFingerprintException()
249249
public function testNormalizePeerFingerprintTypeException()
250250
{
251251
$this->expectException('Symfony\Component\HttpClient\Exception\InvalidArgumentException');
252-
$this->expectExceptionMessage('Option "peer_fingerprint" must be string or array, object given.');
252+
$this->expectExceptionMessage('Option "peer_fingerprint" must be string or array, "object" given.');
253253
$fingerprint = new \stdClass();
254254

255255
$this->normalizePeerFingerprint($fingerprint);

Tests/Response/MockResponseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public function toArrayErrors()
5656
yield [
5757
'content' => '"not an array"',
5858
'responseHeaders' => [],
59-
'message' => 'JSON content was expected to decode to an array, string returned for "https://example.com/file.json".',
59+
'message' => 'JSON content was expected to decode to an array, "string" returned for "https://example.com/file.json".',
6060
];
6161

6262
yield [
6363
'content' => '8',
6464
'responseHeaders' => [],
65-
'message' => 'JSON content was expected to decode to an array, integer returned for "https://example.com/file.json".',
65+
'message' => 'JSON content was expected to decode to an array, "integer" returned for "https://example.com/file.json".',
6666
];
6767
}
6868
}

0 commit comments

Comments
 (0)