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] Remove duplicate checks for an array key existing #17069

Merged
merged 1 commit into from
Apr 20, 2020

Conversation

colemanw
Copy link
Member

Overview

Code cleanup - fixes up situations where we check if an array key exists, and then immediately check again.

Before

Double check, first in a conditional, then again with CRM_Utils_Array::value or coalesce.

After

Removed second check. Once is enough.

@civibot
Copy link

civibot bot commented Apr 13, 2020

(Standard links)

@civibot civibot bot added the master label Apr 13, 2020
@colemanw colemanw force-pushed the removeUselessChecks branch from 96f04a3 to 2cfe2cf Compare April 13, 2020 21:12
@colemanw
Copy link
Member Author

retest this please

$customValueCount = $form->_submitValues['hidden_custom_group_count'] ?? NULL;
if (is_array($customValueCount)) {
if (array_key_exists(0, $customValueCount)) {
unset($customValueCount[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what the keys of customValueCount are or why we're unsetting 0? Can't we just array_shift($customValueCount)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what this code does either :/
But at least it's more readable now.

@@ -388,17 +388,15 @@ public function alterDisplay(&$rows) {
}

if (array_key_exists('civicrm_worldregion_name', $values)) {
$region = $values['civicrm_worldregion_name'] ?? NULL;
$region = ($region) ? $region : 'Unassigned';
$region = $values['civicrm_worldregion_name'] ?: 'Unassigned';

This comment was marked as resolved.

This comment was marked as resolved.

else {
$queue_id = $_GET['q'] ?? NULL;
}
$queue_id = $_GET['qid'] ?? $_GET['q'] ?? NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Love that we're supporting CiviCRM <1.7!

@artfulrobot
Copy link
Contributor

artfulrobot commented Apr 15, 2020

@colemanw Wow what a lot of crud you cleaned up - thanks!

(CiviCRM Review Template DEL-1.2)

  • General standards
    • Explain (r-explain)
      • PASS : The goal/problem/solution have been adequately explained in the PR.
    • User impact (r-user)
      • PASS: The change would be intuitive or unnoticeable for a majority of users who work with this feature.
    • Documentation (r-doc)
      • PASS: The changes do not require documentation.
    • Run it (r-run)
      • UNREVIEWED
  • Developer standards
    • Technical impact (r-tech)
      • PASS: All looks good.
    • Code quality (r-code)
      • PASS: The functionality, purpose, and style of the code seems clear+sensible.
    • Maintainability (r-maint)
      • PASS: The change sufficiently improves test coverage, or the change is trivial enough that it does not require tests.
    • Test results (r-test)
      • UNREVIEWED

@colemanw
Copy link
Member Author

Thanks so much for the review @artfulrobot !

@colemanw colemanw merged commit e6c8c50 into civicrm:master Apr 20, 2020
@colemanw colemanw deleted the removeUselessChecks branch April 20, 2020 00:51
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.

2 participants