-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
Fix continue / break PHP 7.3 warnings #13066
Conversation
(Standard links)
|
@ejegg What do you think about extracting the big switch clause instead? for the first one e.g something like
where the extracted function looks like
|
CRM/Core/BAO/CustomGroup.php
Outdated
@@ -1564,7 +1564,7 @@ public static function postProcess(&$groupTree, &$params, $skipFile = FALSE) { | |||
|
|||
case 'File': | |||
if ($skipFile) { | |||
continue; | |||
continue 2; |
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.
Looking at the code I think this one should be a 'break'
CRM/Price/BAO/PriceSet.php
Outdated
@@ -737,7 +737,7 @@ public static function processAmount($fields, &$params, &$lineItem, $component = | |||
case 'Radio': | |||
//special case if user select -none- | |||
if ($params["price_{$id}"] <= 0) { | |||
continue; | |||
continue 2; |
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.
I think this should probably be a break too
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.
Ah, cool, I like the thought of extracting the whole thing
OK, updated to use 'break' in the CustomGroup and PriceSet, and to extract the function more or less like you suggested |
Ahh, whitespace warnings from checkstyle. I'll fix those, and pull the extra line into the function |
PHP 7.3 started warning on 'continue' statements inside switches, where they act just like 'break' statements. To actually continue the enclosing loop, it would have to be 'continue 2'. Since that's a weird syntax and these two cases have nothing after the switch, I've replaced them here with break.
PHP 7.3 warns if a continue statement is used inside a switch, where it functions as a break statement. This patch extracts the switch from the loop, and also fixes the fall-through error from civicrm_campaign to default, moving the civicrm_website case out of the way.
test this please |
I re-did the same extraction & compared any differences between my result & this result & they were all cosmetic. Tests coverage is good over this code & approach is sensible. Merging. yay to supporting php 7.3 |
Overview
PHP 7.3 emits warnings on ambiguous use of 'continue' where it
serves as a 'break' statement.
In all of these cases it looked like 'break' would have also worked
since there was nothing after the end of the switch statement but
before the end of the loop. But I used continue 2 to be a bit safer
about it, in case people add more code there.
Before
PHP 7.3 emits warnings, causing tests to fail under strict conditions
After
Fewer warnings
Technical Details
If the PR introduces noteworthy technical changes, please describe them here. Provide code snippets if necessary
Comments
Note that in the contact Query there seems to be a fallthrough bug
with campaign, where a comment says things not matching the tested
cases should fall through to default, but 'website' has been added
in between.