Skip to content

Conversation

@Meldiron
Copy link
Contributor

@Meldiron Meldiron commented Feb 10, 2026

Summary by CodeRabbit

  • Refactor

    • Iteration over collections now supports generator-style consumption, allowing callers to iterate records directly without supplying a callback. Docblocks and iteration flow updated to reflect the new iterative usage and behavior.
  • Tests

    • Added end-to-end tests covering iteration over empty collections and iterative retrieval across existing data to validate behavior when no callback is provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Warning

Rate limit exceeded

@Meldiron has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 42 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

Walkthrough

Adds a new public iterate(string $collection, array $queries = [], string $forPermission = Database::PERMISSION_READ): \Generator method to yield documents; refactors foreach(...) to delegate to iterate() and invoke the optional callback per yielded document.

Changes

Cohort / File(s) Summary
Database iteration
src/Database/Database.php
Added iterate(...) : \Generator to yield documents from a collection; updated foreach(...) to delegate to the generator and call the provided callback for each yielded document. Docblock updated.
Foreach tests
tests/e2e/Adapter/Scopes/DocumentTests.php
Extended tests: foreach over an empty collection (limit) and foreach used without a callback to consume generator results from movies (limit verifies expected counts).
Manifests
composer.json, manifest_file
Test/manifest-related lines updated (metadata changes).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I nibble rows and gently yield,

No extra call, the stream revealed.
A generator trail where documents play,
I hop and hand them, one by one, all day. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: introducing a generator-based approach using yield for the forEach() method, which matches the core implementation changes shown in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 feat-foreach-generator

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/e2e/Adapter/Scopes/DocumentTests.php`:
- Around line 4017-4026: The test creates an empty collection 'moviesEmpty' but
the foreach iterates 'movies', causing the assertion to fail; update the call to
$database->foreach(...) to pass 'moviesEmpty' (keeping the existing queries:
[Query::limit(2)] and the rest of the loop intact) so the loop iterates the
newly created empty collection and the count assertion becomes valid.

Copy link

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 PR updates Database::foreach() to support iterating documents via yield when no callback is provided, and extends the E2E tests to cover the new iteration mode (including empty collections).

Changes:

  • Changed Database::foreach() signature to allow a nullable callback and to return a \Generator.
  • Added yielding behavior when no callback is provided.
  • Added E2E tests for iterating with no callback (empty and non-empty collections).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Database/Database.php Adds generator-based iteration mode to foreach() when no callback is provided.
tests/e2e/Adapter/Scopes/DocumentTests.php Adds coverage for callback-less foreach() usage and empty-collection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/Database/Database.php`:
- Around line 7876-7887: The PHPDoc for the method iterate() is out of sync with
its signature: remove the stale "@param callable $callback" entry and update the
description to state that the method yields documents via a Generator for the
given $collection and $queries; keep or adjust the existing `@param` annotations
to only list "string $collection", "array<Query> $queries", and "string
$forPermission" (default Database::PERMISSION_READ), retain "@return \Generator"
and any relevant `@throws`, and ensure the docblock accurately describes that
iterate() yields results rather than accepting a callback.

@abnegate abnegate merged commit 93025fd into main Feb 11, 2026
32 of 33 checks passed
@abnegate abnegate deleted the feat-foreach-generator branch February 11, 2026 05:45
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.

3 participants