Conversation
WalkthroughThe changes in the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (4)
wp-content/civi-extensions/goonjcustom/Civi/InductionService.php (4)
Line range hint
509-511: Fix array comparison syntax errorThe array comparison syntax is incorrect and will cause unexpected behavior.
- if ($contacts['contact_sub_type' === 'Volunteer']) { + if (in_array('Volunteer', $contacts['contact_sub_type'] ?? [])) {
Line range hint
392-397: Extract duplicate template fetching logicThe pattern for fetching message templates is repeated across multiple methods. Consider extracting this into a reusable method.
+ private static function getMessageTemplate($templatePattern) { + return MessageTemplate::get(FALSE) + ->addSelect('id', 'msg_subject') + ->addWhere('msg_title', 'LIKE', $templatePattern) + ->setLimit(1) + ->execute() + ->single(); + }Also applies to: 576-582, 783-789
Line range hint
849-922: Simplify induction type determination logicThe
fetchTypeOfInductionmethod is complex and hard to maintain. Consider:
- Using configuration for state/city mappings
- Extracting the city formatting logic
- Simplifying the nested conditions
+ private static $OFFLINE_INDUCTION_CITIES = ['patna', 'ranchi', 'bhubaneshwar']; + private static $MIXED_INDUCTION_STATES = ['Bihar', 'Jharkhand', 'Orissa']; + + private static function formatCity($city) { + return ucwords(strtolower($city ?? '')); + }
Line range hint
12-24: Consider using enum for activity statusesThe class uses multiple string constants for activity statuses. Consider using an enum (or class constants) to prevent typos and improve maintainability.
+ private static $ACTIVITY_STATUS = [ + 'TO_BE_SCHEDULED' => 'To be scheduled', + 'SCHEDULED' => 'Scheduled', + 'COMPLETED' => 'Completed', + 'CANCELLED' => 'Cancelled', + 'NO_SHOW' => 'No_show', + ];
| $contacts = Contact::get(FALSE) | ||
| ->addSelect('Individual_fields.Induction_Reschedule_Email_Sent') | ||
| ->addWhere('id', '=',$scheduledInductionActivity['source_contact_id'] ) | ||
| ->addWhere('id', '=',$activity['source_contact_id'] ) |
There was a problem hiding this comment.
Fix indentation
The line is incorrectly indented, breaking the consistent code style.
- ->addWhere('id', '=',$activity['source_contact_id'] )
+ ->addWhere('id', '=', $activity['source_contact_id'])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ->addWhere('id', '=',$activity['source_contact_id'] ) | |
| ->addWhere('id', '=', $activity['source_contact_id']) |
Summary by CodeRabbit