Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Aug 20, 2025

The Stringable interface was added in PHP 8.0. It makes it explicit that the class implements the magic method __toString.

@Copilot Copilot AI review requested due to automatic review settings August 20, 2025 13:58
@GromNaN GromNaN requested a review from a team as a code owner August 20, 2025 13:58
@GromNaN GromNaN requested a review from paulinevos August 20, 2025 13:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements explicit Stringable interface usage across MongoDB PHP driver classes that implement the __toString magic method. This follows PHP 8.0 best practices by making the string conversion capability explicit through interface implementation.

  • Adds explicit Stringable interface implementation to core classes (Client, Database, Collection) and model classes (IndexInput, IndexInfo)
  • Updates Rector configuration to enable PHP 8.0 features and configure the StringableForToStringRector
  • Fixes a minor bug in test code by adding missing separator parameter to implode()

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Client.php Adds Stringable interface implementation to Client class
src/Database.php Adds Stringable interface implementation to Database class
src/Collection.php Adds Stringable interface implementation to Collection class
src/Model/IndexInput.php Adds Stringable interface implementation to IndexInput class
src/Model/IndexInfo.php Adds Stringable interface implementation to IndexInfo class
rector.php Updates Rector configuration to enable PHP 8.0 features and configure StringableForToStringRector
tests/Model/BSONIteratorTest.php Fixes implode() call by adding missing separator parameter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -19,7 +19,7 @@ class BSONIteratorTest extends TestCase
#[DataProvider('provideTypeMapOptionsAndExpectedDocuments')]
public function testValidValues(?array $typeMap, array $expectedDocuments): void
{
$binaryString = implode(array_map(
$binaryString = implode('', array_map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implode() suggests this alternative syntax is still supported, provided the separator string is empty and named arguments aren't utilized. No objection here, but I'm curious what prompted this change. Was it tooling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's prompted by rector. I expect the alternative syntax could be deprecated one day.

@GromNaN GromNaN merged commit 6fe2c02 into mongodb:v2.x Aug 27, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants