Skip to content

Commit 1e4a167

Browse files
committed
Leverage PHP 8.0 string functions
1 parent d2f3766 commit 1e4a167

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function create_field_path_type_map(array $typeMap, string $fieldPath): array
497497
/* Special case if we want to convert an array, in which case we need to
498498
* ensure that the field containing the array is exposed as an array,
499499
* instead of the type given in the type map's array key. */
500-
if (substr($fieldPath, -2, 2) === '.$') {
500+
if (str_ends_with($fieldPath, '.$')) {
501501
$typeMap['fieldPaths'][substr($fieldPath, 0, -2)] = 'array';
502502
}
503503

tests/UnifiedSpecTests/Constraint/Matches.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private static function getOperatorName(BSONDocument $document): string
373373
{
374374
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
375375
foreach ($document as $key => $_) {
376-
if (strpos((string) $key, '$$') === 0) {
376+
if (str_starts_with((string) $key, '$$')) {
377377
return $key;
378378
}
379379
}
@@ -394,7 +394,7 @@ private static function isOperator(BSONDocument $document): bool
394394

395395
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
396396
foreach ($document as $key => $_) {
397-
return strpos((string) $key, '$$') === 0;
397+
return str_starts_with((string) $key, '$$');
398398
}
399399

400400
throw new LogicException('should not reach this point');

tests/UnifiedSpecTests/UnifiedTestRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private function createContext(): Context
528528
// We assume the internal client URI has multiple mongos hosts
529529
$multiMongosUri = $this->internalClientUri;
530530

531-
if (strpos($multiMongosUri, 'mongodb+srv://') === 0) {
531+
if (str_starts_with($multiMongosUri, 'mongodb+srv://')) {
532532
/* TODO: If an SRV URI is provided, we can consider connecting and
533533
* checking the topology for multiple mongoses and then selecting a
534534
* single mongos to reconstruct a single mongos URI; however, that

tools/connect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function getHosts(string $uri): array
44
{
5-
if (strpos($uri, '://') === false) {
5+
if (!str_contains($uri, '://')) {
66
return [$uri];
77
}
88

tools/detect-extension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ function grepIniFile(string $filename, string $extension): int
55
$lines = [];
66

77
foreach (new SplFileObject($filename) as $i => $line) {
8-
if (strpos($line, 'extension') === false) {
8+
if (!str_contains($line, 'extension')) {
99
continue;
1010
}
1111

12-
if (strpos($line, $extension) === false) {
12+
if (!str_contains($line, $extension)) {
1313
continue;
1414
}
1515

0 commit comments

Comments
 (0)