Add null safety checks to prevent PHP warnings#4905
Add null safety checks to prevent PHP warnings#4905GaryJones wants to merge 2 commits intobuddyboss:releasefrom
Conversation
Four small fixes for undefined property/variable warnings and null parameter deprecations on PHP 8.1+: 1. Null-coalescing fallback for missing title_required property on activity objects (bp-groups-activity.php). 2. Null-coalescing fallback before passing bb_notification_small_icon() result to wp_kses_post() (bp-notifications-functions.php). 3. Early return in profile completion widget when user_progress is empty or missing completion_percentage key (class-bp-xprofile-profile-completion-widget.php). 4. Initialise $result to empty array before conditional assignment in topics manager (class-bb-topics-manager.php).
|
@claude Review the PR |
|
Claude finished @chetansatasiya's task in 1m 36s —— View job PR Review: Add null safety checks to prevent PHP warnings
Overall assessment: ✅ Looks good — all four fixes are correct, minimal, and safe. The PR addresses real PHP 8.1+ warnings/deprecation notices without changing behaviour on the happy path. Here are observations per file:
|
Problem
Four places in the codebase lack null/undefined checks, producing PHP warnings or deprecation notices on PHP 8.1+.
1. Undefined
title_requiredproperty on activity objectsIn
bp-groups/bp-groups-activity.php, when updating a group activity, the code accesses$activity->title_requiredwithout a fallback. If the property doesn't exist on the activity object, PHP emits an undefined property warning.Fix: Add
?? falsenull-coalescing fallback.2. Null passed to
wp_kses_post()from notification iconIn
bp-notifications/bp-notifications-functions.php,bb_notification_small_icon()can returnnull, which is then passed directly towp_kses_post(). On PHP 8.1+, this triggers a deprecation warning sincewp_kses_post()expects a string.Fix: Add
?? ''null-coalescing fallback.3. Missing progress data in profile completion widget
In
class-bp-xprofile-profile-completion-widget.php, the widget accesses$user_progress['completion_percentage']without checking whether$user_progressis populated or the key exists. When no applicable profile fields are configured, this produces undefined key warnings.Fix: Add an early return when
$user_progressis empty or missing thecompletion_percentagekey.4. Uninitialised
$resultvariable in topics managerIn
class-bb-topics-manager.php, the$resultvariable is only assigned inside a conditional block (if ( 'migrate' === $migrate_type && $new_topic_id )). When the condition is false,$resultis undefined for any subsequent code that references it.Fix: Initialise
$result = array()before the conditional.Test plan
title_requiredis not set on the activity object — no PHP warningbb_notification_small_icon()returns null — no deprecation notice