Skip to content

Commit

Permalink
Use str_contains where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Dec 19, 2024
1 parent 388acd9 commit 4f637ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
use function parse_str;
use function random_bytes;
use function sprintf;
use function strpos;
use function strstr;
use function str_contains;
use function strtr;
use function substr;
use function trim;
Expand Down Expand Up @@ -514,7 +513,7 @@ protected function appendQuery(string $url, string $query): string
$query = trim($query, '?&');

if ($query) {
$glue = strstr($url, '?') === false ? '?' : '&';
$glue = !str_contains($url, '?') ? '?' : '&';

return $url . $glue . $query;
}
Expand Down Expand Up @@ -828,7 +827,7 @@ protected function parseResponse(ResponseInterface $response): array | string
$content = (string) $response->getBody();
$type = $this->getContentType($response);

if (strpos($type, 'urlencoded') !== false) {
if (str_contains($type, 'urlencoded')) {
parse_str($content, $parsed);

/** @var array<string, string> */
Expand All @@ -841,7 +840,7 @@ protected function parseResponse(ResponseInterface $response): array | string
try {
return $this->parseJson($content);
} catch (UnexpectedValueException $e) {
if (strpos($type, 'json') !== false) {
if (str_contains($type, 'json')) {
throw $e;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tool/ArrayAccessorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use function explode;
use function is_array;
use function is_string;
use function strpos;
use function str_contains;

/**
* Provides generic array navigation tools.
Expand All @@ -40,7 +40,7 @@ private function getValueByKey(array $data, mixed $key, mixed $default = null):
return $default;
}

if (strpos($key, '.') !== false) {
if (str_contains($key, '.')) {
$keys = explode('.', $key);

foreach ($keys as $innerKey) {
Expand Down
4 changes: 2 additions & 2 deletions test/src/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
use function parse_str;
use function parse_url;
use function preg_match;
use function strpos;
use function str_contains;
use function time;
use function uniqid;

Expand Down Expand Up @@ -124,7 +124,7 @@ public function testAuthorizationUrlStateParam(): void
'state' => 'XXX',
]);

$this->assertTrue(strpos($authUrl, 'state=XXX') !== false);
$this->assertTrue(str_contains($authUrl, 'state=XXX'));
}

/**
Expand Down

0 comments on commit 4f637ec

Please sign in to comment.