Skip to content

Commit 29ff82d

Browse files
Merge branch '5.2' into 5.3
* 5.2: Leverage str_contains/str_starts_with Leverage str_ends_with
2 parents ff70f84 + 0ea306d commit 29ff82d

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

CurlHttpClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function request(string $method, string $url, array $options = []): Respo
272272
if ($options['bindto']) {
273273
if (file_exists($options['bindto'])) {
274274
$curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
275-
} elseif (0 !== strpos($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
275+
} elseif (!str_starts_with($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/', $options['bindto'], $matches)) {
276276
$curlopts[\CURLOPT_INTERFACE] = $matches[1];
277277
$curlopts[\CURLOPT_LOCALPORT] = $matches[2];
278278
} else {
@@ -382,7 +382,7 @@ private function handlePush($parent, $pushed, array $requestHeaders, int $maxPen
382382
// curl before 7.65 doesn't validate the pushed ":authority" header,
383383
// but this is a MUST in the HTTP/2 RFC; let's restrict pushes to the original host,
384384
// ignoring domains mentioned as alt-name in the certificate for now (same as curl).
385-
if (0 !== strpos($origin, $url.'/')) {
385+
if (!str_starts_with($origin, $url.'/')) {
386386
$this->logger && $this->logger->debug(sprintf('Rejecting pushed response from "%s": server is not authoritative for "%s"', $origin, $url));
387387

388388
return \CURL_PUSH_DENY;
@@ -493,7 +493,7 @@ private static function createRedirectResolver(array $options, string $host): \C
493493
private function findConstantName(int $opt): ?string
494494
{
495495
$constants = array_filter(get_defined_constants(), static function ($v, $k) use ($opt) {
496-
return $v === $opt && 'C' === $k[0] && (0 === strpos($k, 'CURLOPT_') || 0 === strpos($k, 'CURLINFO_'));
496+
return $v === $opt && 'C' === $k[0] && (str_starts_with($k, 'CURLOPT_') || str_starts_with($k, 'CURLINFO_'));
497497
}, \ARRAY_FILTER_USE_BOTH);
498498

499499
return key($constants);

Exception/HttpExceptionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(ResponseInterface $response)
3232
$httpCodeFound = false;
3333
$isJson = false;
3434
foreach (array_reverse($response->getInfo('response_headers')) as $h) {
35-
if (0 === strpos($h, 'HTTP/')) {
35+
if (str_starts_with($h, 'HTTP/')) {
3636
if ($httpCodeFound) {
3737
break;
3838
}

HttpClientTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
227227
$alternatives = [];
228228

229229
foreach ($defaultOptions as $key => $v) {
230-
if (levenshtein($name, $key) <= \strlen($name) / 3 || false !== strpos($key, $name)) {
230+
if (levenshtein($name, $key) <= \strlen($name) / 3 || str_contains($key, $name)) {
231231
$alternatives[] = $key;
232232
}
233233
}
@@ -494,7 +494,7 @@ private static function parseUrl(string $url, array $query = [], array $allowedS
494494
continue;
495495
}
496496

497-
if (false !== strpos($parts[$part], '%')) {
497+
if (str_contains($parts[$part], '%')) {
498498
// https://tools.ietf.org/html/rfc3986#section-2.3
499499
$parts[$part] = preg_replace_callback('/%(?:2[DE]|3[0-9]|[46][1-9A-F]|5F|[57][0-9A]|7E)++/i', function ($m) { return rawurldecode($m[0]); }, $parts[$part]);
500500
}
@@ -522,11 +522,11 @@ private static function removeDotSegments(string $path)
522522
$result = '';
523523

524524
while (!\in_array($path, ['', '.', '..'], true)) {
525-
if ('.' === $path[0] && (0 === strpos($path, $p = '../') || 0 === strpos($path, $p = './'))) {
525+
if ('.' === $path[0] && (str_starts_with($path, $p = '../') || str_starts_with($path, $p = './'))) {
526526
$path = substr($path, \strlen($p));
527-
} elseif ('/.' === $path || 0 === strpos($path, '/./')) {
527+
} elseif ('/.' === $path || str_starts_with($path, '/./')) {
528528
$path = substr_replace($path, '/', 0, 3);
529-
} elseif ('/..' === $path || 0 === strpos($path, '/../')) {
529+
} elseif ('/..' === $path || str_starts_with($path, '/../')) {
530530
$i = strrpos($result, '/');
531531
$result = $i ? substr($result, 0, $i) : '';
532532
$path = substr_replace($path, '/', 0, 4);

NativeHttpClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public function request(string $method, string $url, array $options = []): Respo
7171
if (file_exists($options['bindto'])) {
7272
throw new TransportException(__CLASS__.' cannot bind to local Unix sockets, use e.g. CurlHttpClient instead.');
7373
}
74-
if (0 === strpos($options['bindto'], 'if!')) {
74+
if (str_starts_with($options['bindto'], 'if!')) {
7575
throw new TransportException(__CLASS__.' cannot bind to network interfaces, use e.g. CurlHttpClient instead.');
7676
}
77-
if (0 === strpos($options['bindto'], 'host!')) {
77+
if (str_starts_with($options['bindto'], 'host!')) {
7878
$options['bindto'] = substr($options['bindto'], 5);
7979
}
8080
}
@@ -423,7 +423,7 @@ private static function configureHeadersAndProxy($context, string $host, array $
423423
foreach ($proxy['no_proxy'] as $rule) {
424424
$dotRule = '.'.ltrim($rule, '.');
425425

426-
if ('*' === $rule || $host === $rule || substr($host, -\strlen($dotRule)) === $dotRule) {
426+
if ('*' === $rule || $host === $rule || str_ends_with($host, $dotRule)) {
427427
stream_context_set_option($context, 'http', 'proxy', null);
428428
stream_context_set_option($context, 'http', 'request_fulluri', false);
429429
stream_context_set_option($context, 'http', 'header', $requestHeaders);

Response/CurlResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private static function parseHeaderLine($ch, string $data, array &$info, array &
381381
return \strlen($data);
382382
}
383383

384-
if (0 !== strpos($data, 'HTTP/')) {
384+
if (!str_starts_with($data, 'HTTP/')) {
385385
if (0 === stripos($data, 'Location:')) {
386386
$location = trim(substr($data, 9));
387387
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
"php-http/async-client-implementation": "*",
1919
"php-http/client-implementation": "*",
2020
"psr/http-client-implementation": "1.0",
21-
"symfony/http-client-implementation": "2.4"
21+
"symfony/http-client-implementation": "2.4",
22+
"symfony/polyfill-php80": "^1.16"
2223
},
2324
"require": {
2425
"php": ">=7.2.5",
2526
"psr/log": "^1|^2|^3",
2627
"symfony/deprecation-contracts": "^2.1",
2728
"symfony/http-client-contracts": "^2.4",
2829
"symfony/polyfill-php73": "^1.11",
29-
"symfony/polyfill-php80": "^1.15",
30+
"symfony/polyfill-php80": "^1.16",
3031
"symfony/service-contracts": "^1.0|^2"
3132
},
3233
"require-dev": {

0 commit comments

Comments
 (0)