Skip to content

Abstract getDriver#849

Merged
abnegate merged 3 commits intomainfrom
pool-adapter-get-driver
Mar 31, 2026
Merged

Abstract getDriver#849
abnegate merged 3 commits intomainfrom
pool-adapter-get-driver

Conversation

@fogelito
Copy link
Copy Markdown
Contributor

@fogelito fogelito commented Mar 31, 2026

Summary by CodeRabbit

  • Refactor
    • Standardized how database adapters expose their underlying drivers across implementations.
    • Deprecated a legacy driver accessor in the SQL adapter in favor of the new standardized accessor.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: faada804-c4a2-4d93-86a9-be29080d01e1

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5a378 and 9f8b220.

📒 Files selected for processing (4)
  • src/Database/Adapter.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/SQL.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Database/Adapter.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/SQL.php

📝 Walkthrough

Walkthrough

Added a new abstract public method getDriver(): mixed to the Adapter base class; concrete adapters (Mongo, SQL, Pool) now implement getDriver. SQL::getPDO() is marked deprecated in favor of getDriver().

Changes

Cohort / File(s) Summary
Base Adapter
src/Database/Adapter.php
Added abstract public function getDriver(): mixed; to Adapter.
Concrete Adapters
src/Database/Adapter/Mongo.php, src/Database/Adapter/SQL.php, src/Database/Adapter/Pool.php
Added public function getDriver(): mixed implementations: Mongo returns its client instance, SQL returns $this->pdo and marks getPDO() as @deprecated, Pool delegates via existing delegate(__FUNCTION__, func_get_args()).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
A tiny hop, a new-defined gate,
Drivers shown by each adapter's trait,
SQL bows out of the old getPDO,
Mongo and Pool now gladly show,
A unified call—swift and great.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.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 'Abstract getDriver' directly and clearly describes the main change: introducing an abstract getDriver() method as a new extension point in the base Adapter class.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pool-adapter-get-driver

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.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR introduces a getDriver(): mixed abstract method on the base Adapter class, then implements it across all three concrete adapter families (SQL, Mongo, Pool). The change standardises the way callers access the underlying database driver and correctly deprecates the legacy SQL::getPDO() accessor.

Key changes:

  • Adapter.php: adds the abstract public function getDriver(): mixed contract.
  • SQL.php: adds a public getDriver() returning $this->pdo; marks getPDO() as @deprecated.
  • Mongo.php: adds getDriver() returning $this->client with a correct docblock.
  • Pool.php: adds getDriver() that correctly returns the result of delegate(), ensuring the underlying driver from the pooled adapter is returned rather than the Pool wrapper itself.

Previous concerns about the Pool implementation silently discarding the return value have been addressed. One remaining minor note: the driver returned by Pool::getDriver() outside a transaction context comes from a borrowed-then-released connection, which callers should be aware of if they intend to use the driver object directly for subsequent operations.

Confidence Score: 5/5

This PR is safe to merge; all changes are additive and the prior P1 concern in Pool has been fixed.

No P0 or P1 issues remain. The only finding is a P2 documentation/design note about Pool::getDriver() semantics outside a transaction, which does not affect correctness in typical usage patterns.

No files require special attention.

Important Files Changed

Filename Overview
src/Database/Adapter.php Adds abstract getDriver(): mixed method to the base adapter, establishing the contract all adapters must fulfil.
src/Database/Adapter/Mongo.php Implements getDriver() returning $this->client with a correct docblock noting the Mongo client return value.
src/Database/Adapter/Pool.php Implements getDriver() by delegating to the pool; correctly returns the delegate result. Outside a transaction the returned driver object comes from a borrowed-then-released connection.
src/Database/Adapter/SQL.php Adds public getDriver() returning $this->pdo and deprecates the legacy protected getPDO() accessor.

Reviews (2): Last reviewed commit: "Change to public" | Re-trigger Greptile

Copy link
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Database/Adapter/Mongo.php`:
- Around line 80-83: The docblock for getDriver() incorrectly mentions "PDO" and
should reflect that it returns the Mongo client; update the comment and `@return`
annotation on the getDriver() method (and any mention of $this->client) to
reference the correct type (e.g. \MongoDB\Client or the actual Mongo client
class used) and remove any PDO wording to avoid confusion.

In `@src/Database/Adapter/Pool.php`:
- Around line 73-78: getDriver() currently calls $this->delegate(__FUNCTION__,
func_get_args()) and then returns $this (dropping the delegated result); change
it to return the delegate's result so the underlying driver is returned. Update
getDriver() to return the value from $this->delegate(...) (or store it in a
$result variable and return that) while keeping the existing __FUNCTION__ and
func_get_args() invocation so the delegation behavior is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c675658-0631-4633-942b-7218063056c2

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1b4b4 and 2d5a378.

📒 Files selected for processing (4)
  • src/Database/Adapter.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/SQL.php

@abnegate abnegate merged commit 72ee161 into main Mar 31, 2026
19 checks passed
@abnegate abnegate deleted the pool-adapter-get-driver branch March 31, 2026 15:52
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