Fix: make methods protected for extending#10617
Conversation
📝 WalkthroughWalkthroughThis change updates src/Appwrite/Platform/Workers/StatsUsage.php by adjusting visibility from private to protected for several class members. The affected members are properties Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 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 |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Appwrite/Platform/Workers/StatsUsage.php (2)
21-26: LGTM! Consider adding documentation for extension points.The visibility changes enable subclassing and extension of this worker class, which aligns with the PR objective. The pattern is consistent with other workers in the codebase (e.g.,
Audits.php).However, consider adding PHPDoc comments to document:
- Which properties are safe for subclasses to access or modify
- Any constraints or invariants that subclasses should maintain
- Whether direct property modification is intended or if accessor methods should be added in the future
This will help prevent subclasses from inadvertently breaking internal state consistency.
Also applies to: 32-32, 38-38
198-362: LGTM! Consider future refactoring for better extensibility.Changing
reduce()to protected enables subclasses to customize metric reduction logic, which aligns with the extensibility goal.As an optional future improvement, consider refactoring this method to use a strategy pattern or template method pattern with smaller, overridable methods for each document type case. This would allow subclasses to extend specific reduction behaviors without overriding the entire method, reducing the risk of breaking core functionality.
For example:
protected function reduce(Document $project, Document $document, array &$metrics, callable $getProjectDB): void { $collection = $document->getCollection(); switch (true) { case $collection === 'users': $this->reduceUsers($project, $document, $metrics, $getProjectDB); break; case $collection === 'databases': $this->reduceDatabases($project, $document, $metrics, $getProjectDB); break; // ... other cases } } protected function reduceUsers(Document $project, Document $document, array &$metrics, callable $getProjectDB): void { // Current users case logic }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Appwrite/Platform/Workers/StatsUsage.php(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Appwrite/Platform/Workers/StatsUsage.php (3)
src/Appwrite/Platform/Workers/Audits.php (1)
getBatchSize(28-31)src/Appwrite/Utopia/Response/Model/Document.php (1)
Document(8-112)app/realtime.php (1)
getProjectDB(76-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: E2E Service Test (Teams)
- GitHub Check: E2E Service Test (Tokens)
- GitHub Check: E2E Service Test (VCS)
- GitHub Check: E2E Service Test (Storage)
- GitHub Check: E2E Service Test (Realtime)
- GitHub Check: E2E Service Test (Console)
- GitHub Check: E2E Service Test (Health)
- GitHub Check: E2E Service Test (Functions)
- GitHub Check: E2E Service Test (Locale)
- GitHub Check: E2E Service Test (FunctionsSchedule)
- GitHub Check: E2E Service Test (Account)
- GitHub Check: E2E Service Test (Databases/TablesDB)
- GitHub Check: E2E Service Test (Avatars)
- GitHub Check: E2E Service Test (GraphQL)
- GitHub Check: E2E Service Test (Databases/Legacy)
- GitHub Check: E2E Service Test (Dev Keys)
- GitHub Check: E2E Service Test (Site Screenshots)
- GitHub Check: Unit Test
- GitHub Check: E2E General Test
- GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Workers/StatsUsage.php (1)
104-109: LGTM! Consistent with codebase pattern.Making
getBatchSize()protected allows subclasses to customize batch sizing logic, which is a reasonable extension point. This follows the same pattern used insrc/Appwrite/Platform/Workers/Audits.php.
✨ Benchmark results
⚡ Benchmark Comparison
|
What does this PR do?
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)
Related PRs and Issues
Checklist