Skip to content

Commit 5c147fd

Browse files
authored
Leverage PHP 8.0 string functions (#1274)
1 parent d2f3766 commit 5c147fd

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/functions.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use function is_string;
4646
use function MongoDB\BSON\fromPHP;
4747
use function MongoDB\BSON\toPHP;
48+
use function str_ends_with;
4849
use function substr;
4950

5051
/**
@@ -497,7 +498,7 @@ function create_field_path_type_map(array $typeMap, string $fieldPath): array
497498
/* Special case if we want to convert an array, in which case we need to
498499
* ensure that the field containing the array is exposed as an array,
499500
* instead of the type given in the type map's array key. */
500-
if (substr($fieldPath, -2, 2) === '.$') {
501+
if (str_ends_with($fieldPath, '.$')) {
501502
$typeMap['fieldPaths'][substr($fieldPath, 0, -2)] = 'array';
502503
}
503504

tests/UnifiedSpecTests/Constraint/Matches.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
use function PHPUnit\Framework\logicalOr;
3838
use function range;
3939
use function sprintf;
40-
use function strpos;
40+
use function str_starts_with;
4141
use function strrchr;
4242

4343
/**
@@ -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

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use function PHPUnit\Framework\assertNotFalse;
3636
use function preg_replace;
3737
use function sprintf;
38+
use function str_starts_with;
3839
use function strlen;
3940
use function strpos;
4041
use function substr_replace;
@@ -528,7 +529,7 @@ private function createContext(): Context
528529
// We assume the internal client URI has multiple mongos hosts
529530
$multiMongosUri = $this->internalClientUri;
530531

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

0 commit comments

Comments
 (0)