Skip to content

Fix toArray() recursive nested stdClass conversion#32

Merged
abnegate merged 3 commits intomainfrom
fix/toarray-recursive-conversion
Feb 12, 2026
Merged

Fix toArray() recursive nested stdClass conversion#32
abnegate merged 3 commits intomainfrom
fix/toarray-recursive-conversion

Conversation

@premtsd-code
Copy link
Contributor

@premtsd-code premtsd-code commented Feb 11, 2026

Summary

  • Fixed toArray() in Client.php where the foreach loop assigned recursive results to a local copy ($item) instead of writing back to $ret[$key]
  • Nested stdClass objects now properly convert to arrays at all depths
  • Non-stdClass objects (DateTime, ObjectId, etc.) are preserved and not converted
  • Fixes downstream "Cannot use object of type stdClass as array" errors in Document.php

Summary by CodeRabbit

  • Bug Fixes

    • Improved nested object-to-array conversion in the MongoDB client to correctly handle nested structures, ensuring only arrays and objects are recursively converted while preserving scalar values.
  • Tests

    • Added comprehensive test coverage for nested document and object conversion scenarios, including edge cases with mixed data types and deeply nested structures.

The foreach loop assigned recursive results to a local copy instead
of writing back to the array. Nested stdClass objects survived
conversion, causing 'Cannot use object of type stdClass as array'
errors downstream in Document constructor.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

Warning

Rate limit exceeded

@premtsd-code has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

A new CodeRabbit configuration file is added to define code review filtering rules and set the default base branch for automatic reviews. The toArray method in Client.php is refactored to recursively convert only nested arrays and stdClass objects, while leaving scalar values unchanged. Two new test methods are introduced to verify nested object-to-array conversion behavior across various BSON-like structures and real MongoDB documents.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: fixing the toArray() method to properly handle recursive conversion of nested stdClass objects.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/toarray-recursive-conversion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@abnegate abnegate merged commit 45bedf3 into main Feb 12, 2026
4 checks passed
@abnegate abnegate deleted the fix/toarray-recursive-conversion branch February 12, 2026 05:54
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