-
-
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
[REF] do not needlessly pass as reference, enforce valid param #19478
Conversation
(Standard links)
|
@colemanw are you OK to merge this? |
@eileenmcnaughton I'd be happier if the function had a unit test :) |
@colemanw I guess our tests go through this |
Ok |
This is causing all the PR's to fail tests (CRM_Core_BAO_MessageTemplateTest::testContactTokens). An easy way to see what's happening is to run BEFORE: NULL The second is more correct, and for tokens used in smarty if people are doing something like branching based on that value then typically it would evaluate the same either way since most people write smarty as So the question is the other places this function is used that isn't covered by tests and whether there'd be a difference there. |
It's not used much outside tokens. Maybe here is the only place it would make a difference, if you're importing blanks instead of '0's, but it might be an improvement, i.e. before blanks might overwrite (haven't tested): civicrm-core/CRM/Contact/Import/Parser/Contact.php Lines 1709 to 1716 in 64c5747
|
Oh - the green light was BEFORE I added that test & it was when I was working on that code that I found the function so confusing I guess |
So I am seeing a difference with import in fill mode before and after the patch. Suppose you have a contact that does not have DO NOT PHONE checked. BEFORE: Importing a "1" in the import file checks the DO NOT PHONE setting as expected. The difference seems to be that before the patch it treats the existing value as NULL and so goes ahead and imports it. After the patch it treats the existing value as "0" and so according to fill mode it shouldn't import it. Blanks and "0" behave the same before and after the patch when importing against a contact the DOES have the setting checked, but then that's expected if the effect is on how it treats the existing value. |
elseif ($value = CRM_Utils_Array::value($key, $params)) { | ||
return $value; | ||
public static function retrieveValueRecursive(array $params, string $key) { | ||
if (isset($params[$key])) { |
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.
@demeritcowboy so we need to change this to if (!empty() ) to get no change
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.
A quick run says yes.
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.
OK - I'll put that up
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.
It seems the tests ran before the test that covered this was merged giving a false positive See civicrm#19478 (comment) for rationale
Overview
[REF] do not needlessly pass as reference, enforce valid param
Before
Unnecessary pass-by-reference, array type not enforced
After
pass by ref removed, strict typing on array, simplifed return structure (do not use elseif after a return)
Technical Details
Quietly skipping an invalid param feels like a recipe for weirdness
Comments
This function isn't that heavily used & I couldn't find any cases of calling functions doing anything weird - it would fail hard & fast if there were an issue - probably during tests