Skip to content
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] Minor code clean up #17974

Merged
merged 1 commit into from
Jul 27, 2020
Merged

[REF] Minor code clean up #17974

merged 1 commit into from
Jul 27, 2020

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jul 27, 2020

Overview

This just consolidates a little of the code used to determine if an email receipt should be sent.

Before

$input['is_email_receipt'] always 'wins' if set but it does so by being handled in 2 places

After

$input['is_email_receipt'] is handled onnce.

Technical Details

It's clear that there is more code above that could be pulled into this & combined
with the isEmailReceipt function but I wanted to just offer up a small reviewable change unless
there is reviewer enthusiasm for more

Comments

This just consolidates a little of the code used to determin if an email receipt should be sent.
It's clear that there is more code above that could be pulled into this & combined
with the isEmailReceipt function but I wanted to just offer up a small reviewable change unless
there is reviewer enthusiasm for more
@civibot
Copy link

civibot bot commented Jul 27, 2020

(Standard links)

$isEmailReceipt = !array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1;
if (isset($input['is_email_receipt'])) {
$isEmailReceipt = $input['is_email_receipt'];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing - surely the first line is all that's needed?

isset will always be true if the array key exists, but if the array key exists then $isEmailReceipt will already be correctly set, with the exception of possible different values of truthy. As in it comes down to what values == 1.

I think this is equivalent to these 4 lines?

$isEmailReceipt = $values['is_email_receipt'] ?? 1;

Copy link
Contributor Author

@eileenmcnaughton eileenmcnaughton Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artfulrobot yes - probably - I was focussed on moving existing lines to a new order so we don't do

  • set this
  • set it to something else possibly
  • set it again in case we changed it & didn't mean to (because input overrides $values)

& instead do

  • set it to something else possibly
  • set it to $input['is_email_receipt'] if that has been passed in as it clobbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie. $input always overrides $values - if set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad, sorry. I'd missed that the 2nd if{} was about $input!

@mattwire
Copy link
Contributor

This looks fine as a cleanup

@mattwire mattwire merged commit 29eae0d into civicrm:master Jul 27, 2020
@eileenmcnaughton eileenmcnaughton deleted the receipt branch July 27, 2020 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants