Skip to content

Leverage PHP 8.0 string functions #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use function is_string;
use function MongoDB\BSON\fromPHP;
use function MongoDB\BSON\toPHP;
use function str_ends_with;
use function substr;

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

Expand Down
6 changes: 3 additions & 3 deletions tests/UnifiedSpecTests/Constraint/Matches.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use function PHPUnit\Framework\logicalOr;
use function range;
use function sprintf;
use function strpos;
use function str_starts_with;
use function strrchr;

/**
Expand Down Expand Up @@ -373,7 +373,7 @@ private static function getOperatorName(BSONDocument $document): string
{
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
foreach ($document as $key => $_) {
if (strpos((string) $key, '$$') === 0) {
if (str_starts_with((string) $key, '$$')) {
return $key;
}
}
Expand All @@ -394,7 +394,7 @@ private static function isOperator(BSONDocument $document): bool

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

throw new LogicException('should not reach this point');
Expand Down
3 changes: 2 additions & 1 deletion tests/UnifiedSpecTests/UnifiedTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use function PHPUnit\Framework\assertNotFalse;
use function preg_replace;
use function sprintf;
use function str_starts_with;
use function strlen;
use function strpos;
use function substr_replace;
Expand Down Expand Up @@ -528,7 +529,7 @@ private function createContext(): Context
// We assume the internal client URI has multiple mongos hosts
$multiMongosUri = $this->internalClientUri;

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