-
Notifications
You must be signed in to change notification settings - Fork 41
New sniff to enforce early returns when there are nested conditions #2832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -93,11 +93,13 @@ | |||||||||||||||||
| * @return array | ||||||||||||||||||
| */ | ||||||||||||||||||
| public static function remove_wpforms_nag( $upsell ) { | ||||||||||||||||||
| if ( is_array( $upsell ) ) { | ||||||||||||||||||
| foreach ( $upsell as $k => $plugin ) { | ||||||||||||||||||
| if ( str_contains( $plugin['slug'], 'wpforms' ) ) { | ||||||||||||||||||
| unset( $upsell[ $k ] ); | ||||||||||||||||||
| } | ||||||||||||||||||
| if ( ! is_array( $upsell ) ) { | ||||||||||||||||||
| return $upsell; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| foreach ( $upsell as $k => $plugin ) { | ||||||||||||||||||
| if ( str_contains( $plugin['slug'], 'wpforms' ) ) { | ||||||||||||||||||
| unset( $upsell[ $k ] ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+100
to
103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential error if array element lacks expected structure. The code accesses 🛡️ Suggested defensive check foreach ( $upsell as $k => $plugin ) {
- if ( str_contains( $plugin['slug'], 'wpforms' ) ) {
+ if ( is_array( $plugin ) && isset( $plugin['slug'] ) && str_contains( $plugin['slug'], 'wpforms' ) ) {
unset( $upsell[ $k ] );
}
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,19 +188,21 @@ private static function get_renewal_date() { | |
| // If renewal date doesn't exist, get from the first form creation date. | ||
| $first_form_date = self::get_earliest_form_created_date(); | ||
|
|
||
| if ( $first_form_date ) { | ||
| $renewal_date = gmdate( 'Y-m-d', strtotime( $first_form_date . '+' . self::YEARLY_PERIOD . ' days' ) ); | ||
| if ( ! $first_form_date ) { | ||
| return false; | ||
| } | ||
|
|
||
| // If the first form is more than 1 year in the past, set renewal date to the next 45 days. | ||
| if ( $renewal_date < self::get_date_from_today() ) { | ||
| $renewal_date = self::get_date_from_today( '+' . self::BEFORE_RENEWAL_PERIOD . ' days' ); | ||
| } | ||
| $renewal_date = gmdate( 'Y-m-d', strtotime( $first_form_date . '+' . self::YEARLY_PERIOD . ' days' ) ); | ||
|
|
||
| $options['renewal_date'] = $renewal_date; | ||
| self::save_options( $options ); | ||
| return $renewal_date; | ||
| // If the first form is more than 1 year in the past, set renewal date to the next 45 days. | ||
| if ( $renewal_date < self::get_date_from_today() ) { | ||
| $renewal_date = self::get_date_from_today( '+' . self::BEFORE_RENEWAL_PERIOD . ' days' ); | ||
| } | ||
|
|
||
| $options['renewal_date'] = $renewal_date; | ||
| self::save_options( $options ); | ||
| return $renewal_date; | ||
|
|
||
| return false; | ||
|
Comment on lines
+191
to
206
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unreachable code: After the early return refactoring, the control flow always either:
Line 206 is dead code that should be removed. Proposed fix $options['renewal_date'] = $renewal_date;
self::save_options( $options );
return $renewal_date;
-
- return false;
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreachable code detected.
Line 1242
return $result;is unreachable. All code paths before it either return or terminate:no_plugin_headererrorwp_send_json_error()terminates executionThis appears to be leftover from the refactoring. The line should be removed.
🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents