Make withCache private#915
Conversation
📝 WalkthroughWalkthrough
ChangeswithCache Visibility Change
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR narrows
Confidence Score: 3/5The production Database class is not affected at runtime because withCache was already unused internally, but the change leaves a private method that no production code can reach and whose test coverage relies entirely on reflection into dead code. The method is declared private yet has zero internal callers — it cannot be invoked by any production path. The unit tests now validate a code path that is structurally unreachable in production, so the cache-lease logic they exercise is untested through real call chains. src/Database/Database.php — specifically whether withCache should be wired into find/getDocument or removed entirely given it has no internal callers. Important Files Changed
|
| private function withCache( | ||
| Database $database, | ||
| string $key, | ||
| callable $callback, | ||
| ?string $hash = '', | ||
| ): mixed { | ||
| $method = new \ReflectionMethod(Database::class, 'withCache'); | ||
|
|
||
| /** @var T */ | ||
| return $method->invoke($database, $key, $callback, $hash); | ||
| } | ||
|
|
There was a problem hiding this comment.
Reflection-based test helper is fragile
new \ReflectionMethod(Database::class, 'withCache') will throw a ReflectionException at runtime if the method is renamed or removed, with no compile-time signal. The same helper is duplicated in WithCacheLeaseTest, so a rename would silently break two test files. Consider naming the helper more explicitly (e.g. invokeWithCache) or centralising it in a shared trait so the single 'withCache' string literal is easy to find and update.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/QueryCacheTest.php
Line: 37-48
Comment:
**Reflection-based test helper is fragile**
`new \ReflectionMethod(Database::class, 'withCache')` will throw a `ReflectionException` at runtime if the method is renamed or removed, with no compile-time signal. The same helper is duplicated in `WithCacheLeaseTest`, so a rename would silently break two test files. Consider naming the helper more explicitly (e.g. `invokeWithCache`) or centralising it in a shared trait so the single `'withCache'` string literal is easy to find and update.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/Database/Database.php (1)
8614-8618: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winRemove or wire up
withCachesrc/Database/Database.php:8614
Only reflection-based unit tests reach this helper; no production path calls it, so the private method is dead code unless a public caller is added.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Database/Database.php` around lines 8614 - 8618, The private helper withCache in Database is currently unreachable from production code, so either remove it if it is unused or wire it into a real caller path; if you keep it, add a public/internal method that invokes withCache and ensure the cache key/hash behavior is exercised by an existing Database workflow. Use the withCache method name and related Database call sites to locate the change.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/Database/Database.php`:
- Around line 8614-8618: The private helper withCache in Database is currently
unreachable from production code, so either remove it if it is unused or wire it
into a real caller path; if you keep it, add a public/internal method that
invokes withCache and ensure the cache key/hash behavior is exercised by an
existing Database workflow. Use the withCache method name and related Database
call sites to locate the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b18d3616-fe03-409b-8f77-a472c6fd98db
📒 Files selected for processing (3)
src/Database/Database.phptests/unit/QueryCacheTest.phptests/unit/WithCacheLeaseTest.php
Summary
Database::withCache()privateTests
php -l src/Database/Database.phpphp -l tests/unit/QueryCacheTest.phpphp -l tests/unit/WithCacheLeaseTest.phpgit diff --checkCould not run
composer lintorcomposer formatbecausevendor/bin/pintis unavailable. Local dependency install was blocked by missing PHP extensions and a write permission error while downloading Composer packages.Summary by CodeRabbit
Bug Fixes
Tests