Skip to content

Check if users before attempting to access #66

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

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@
class Zendesk_Zendesk_Block_Adminhtml_Dashboard_Tab_Tickets_Grid_Renderer_Email extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

public function render(Varien_Object $row) {
$users = Mage::registry('zendesk_users') ? Mage::registry('zendesk_users') : array();
$users = Mage::registry('zendesk_users');
$value = (int) $row->getData($this->getColumn()->getIndex());

$found = array_filter($users, function($user) use($value) {
return (int) $user['id'] === $value;
});

if( count($found) ) {

if ($users) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we Just enclose the whole thing in the if block to save on checks?

  if ($users) {
    $found = array_filter($users, function($user) use($value) {
      return (int) $user['id'] === $value;
    });

    if( count($found) ) {
      $user = array_shift($found);
      return $user['email'];
    }
  }
return '';
}

Also can we remove the whitespaces at the end of lines 37, 39, 40

Copy link
Contributor

Choose a reason for hiding this comment

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

As closure functions are supported from PHP >= 5.3.0, I would discourage to use them within Magento code as they are not used anywhere else. It does make use of create_function() or you could just simply iterate over the array with foreach and return $user['email'] when the right user ID was found.

$found = array_filter($users, function($user) use($value) {
return (int) $user['id'] === $value;
});
} else {
return '';
}

if( count($found) ) {
$user = array_shift($found);

return $user['email'];
}
return '';
}
}

return '';
}

}