Skip to content

Commit c8a64b9

Browse files
committed
Merge branch '5.0'
* 5.0: Fix quotes in exception messages Fix quotes in exception messages Fix quotes in exception messages Fix quotes in exception messages Fix quotes in exception messages
2 parents fc2e72b + 2964cc5 commit c8a64b9

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
@@ -49,7 +49,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
4949
$options['buffer'] = static function (array $headers) use ($buffer) {
5050
if (!\is_bool($buffer = $buffer($headers))) {
5151
if (!\is_array($bufferInfo = @stream_get_meta_data($buffer))) {
52-
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)));
52+
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)));
5353
}
5454

5555
if (false === strpbrk($bufferInfo['mode'], 'acew+')) {
@@ -61,7 +61,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
6161
};
6262
} elseif (!\is_bool($buffer)) {
6363
if (!\is_array($bufferInfo = @stream_get_meta_data($buffer))) {
64-
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)));
64+
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)));
6565
}
6666

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

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

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

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

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

114114
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
115-
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'])));
115+
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']).'"'));
116116
}
117117

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

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

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

216216
return $options;
@@ -232,13 +232,13 @@ private static function normalizeHeaders(array $headers): array
232232

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

244244
$values = (array) $values;
@@ -313,7 +313,7 @@ private static function normalizeBody($body)
313313
}
314314

315315
if (!\is_array(@stream_get_meta_data($body))) {
316-
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)));
316+
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)));
317317
}
318318

319319
return $body;
@@ -339,7 +339,7 @@ private static function normalizePeerFingerprint($fingerprint): array
339339
$fingerprint[$algo] = 'pin-sha256' === $algo ? (array) $hash : str_replace(':', '', $hash);
340340
}
341341
} else {
342-
throw new InvalidArgumentException(sprintf('Option "peer_fingerprint" must be string or array, %s given.', \gettype($fingerprint)));
342+
throw new InvalidArgumentException(sprintf('Option "peer_fingerprint" must be string or array, "%s" given.', \gettype($fingerprint)));
343343
}
344344

345345
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
@@ -82,7 +82,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
8282
if ($responses instanceof ResponseInterface) {
8383
$responses = [$responses];
8484
} elseif (!is_iterable($responses)) {
85-
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)));
85+
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)));
8686
}
8787

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

NativeHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
235235
if ($responses instanceof NativeResponse) {
236236
$responses = [$responses];
237237
} elseif (!is_iterable($responses)) {
238-
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)));
238+
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)));
239239
}
240240

241241
return new ResponseStream(NativeResponse::stream($responses, $timeout));
@@ -255,7 +255,7 @@ private static function getBodyAsString($body): string
255255

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

261261
$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)