Skip to content

Commit ba71aa2

Browse files
committed
Leverage str_starts_with(), str_ends_with() and str_contains()
1 parent 6309807 commit ba71aa2

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

AmpHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public function request(string $method, string $url, array $options = []): Respo
8181
}
8282

8383
if ($options['bindto']) {
84-
if (0 === strpos($options['bindto'], 'if!')) {
84+
if (str_starts_with($options['bindto'], 'if!')) {
8585
throw new TransportException(__CLASS__.' cannot bind to network interfaces, use e.g. CurlHttpClient instead.');
8686
}
87-
if (0 === strpos($options['bindto'], 'host!')) {
87+
if (str_starts_with($options['bindto'], 'host!')) {
8888
$options['bindto'] = substr($options['bindto'], 5);
8989
}
9090
}

Chunk/ServerSentEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(string $content)
2929
parent::__construct(-1, $content);
3030

3131
// remove BOM
32-
if (0 === strpos($content, "\xEF\xBB\xBF")) {
32+
if (str_starts_with($content, "\xEF\xBB\xBF")) {
3333
$content = substr($content, 3);
3434
}
3535

DataCollector/HttpClientDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function collectOnClient(TraceableHttpClient $client): array
140140
}
141141
}
142142

143-
if (0 === strpos($contentType, 'image/') && class_exists(ImgStub::class)) {
143+
if (str_starts_with($contentType, 'image/') && class_exists(ImgStub::class)) {
144144
$content = new ImgStub($content, $contentType, '');
145145
} else {
146146
$content = [$content];

Internal/AmpClientState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function request(array $options, Request $request, CancellationToken $can
7676
foreach ($options['proxy']['no_proxy'] as $rule) {
7777
$dotRule = '.'.ltrim($rule, '.');
7878

79-
if ('*' === $rule || $host === $rule || substr($host, -\strlen($dotRule)) === $dotRule) {
79+
if ('*' === $rule || $host === $rule || str_ends_with($host, $dotRule)) {
8080
$options['proxy'] = null;
8181
break;
8282
}

Internal/AmpListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function startSendingRequest(Request $request, Stream $stream): Promise
8181
{
8282
$host = $stream->getRemoteAddress()->getHost();
8383

84-
if (false !== strpos($host, ':')) {
84+
if (str_contains($host, ':')) {
8585
$host = '['.$host.']';
8686
}
8787

Tests/CurlHttpClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CurlHttpClientTest extends HttpClientTestCase
2222
{
2323
protected function getHttpClient(string $testCase): HttpClientInterface
2424
{
25-
if (false !== strpos($testCase, 'Push')) {
25+
if (str_contains($testCase, 'Push')) {
2626
if (!\defined('CURLMOPT_PUSHFUNCTION') || 0x073d00 > ($v = curl_version())['version_number'] || !(\CURL_VERSION_HTTP2 & $v['features'])) {
2727
$this->markTestSkipped('curl <7.61 is used or it is not compiled with support for HTTP/2 PUSH');
2828
}

0 commit comments

Comments
 (0)