Skip to content

Conversation

@kscheirer
Copy link
Contributor

@kscheirer kscheirer commented Apr 9, 2019

In places where count() was being used to test for empty (count($var) == 0) or not empty (count($var) > 0)) they are replaced with empty(). In places where an actual count was needed, the line was no modified.

@kscheirer kscheirer requested review from cnovak and kbielawiec April 9, 2019 00:17
Copy link
Collaborator

@cnovak cnovak left a comment

Choose a reason for hiding this comment

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

Not sure why this is being changed, not description on commit, see comments on sections, but true for all changes. These changes seem to only check for variables being empty, not whether they are arrays or empty arrays.

{
// Find the credential with the max issuedAt attribute which isn't expired.
if (count($credentials) > 0) {
if (!empty($credentials)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This only checks to make sure the var is not empty, but isn't validating that it is an array. Should this validate it is an array before trying to sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we can be sure credentials is an array, since its required by the function declaration. This instance of count() doesnt have to be removed, but I generally went with using empty() instead of count ==0 or count > 0


// Some apps may be misconfigured and need to be populated with their apiproducts based on credential.
if (count($obj->apiProducts) == 0) {
if (empty($obj->apiProducts)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we need to change this for 7.2? Are these vars not arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They probably are arrays, but the general idea here was to use empty() instead of comparing count to 0. This was the strategy employed for drupal 7 core as well, see https://www.drupal.org/project/drupal/issues/2885610

@kscheirer
Copy link
Contributor Author

kscheirer commented Apr 9, 2019

Sorry, should have included an explanation!

Copy link
Collaborator

@kbielawiec kbielawiec left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@cnovak cnovak left a comment

Choose a reason for hiding this comment

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

LGTM

@cnovak cnovak merged commit 93001c7 into master Jul 9, 2019
@cnovak cnovak deleted the php72-mgmt-api branch July 9, 2019 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants