Page MenuHomeDevCentral

Allow to count "null" and "false" values
ClosedPublic

Authored by dereckson on Apr 29 2018, 22:42.

Details

Summary

Legacy codebases can have methods with dual return value:

  • an array when data is found
  • null when no data is found

Then count is called, to ensure there are data.

In modern PHP, this triggers a warning;
count(): Parameter must be an array or an object that implements Countable

This change provides a method to accept also null and false values.
In such case, the 0 value is returned.

This method isn't intended to be totally permissive: if something
else than an array, a Countable, null or false is passed
as parameter, a TypeError error is thrown, even with falsy values.

Test Plan

Tests provided with countable and not countable variables.

Diff Detail

Repository
rKOT Keruald OmniTools
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
dereckson requested review of this revision.Apr 29 2018, 22:42
dereckson created this revision.
dereckson accepted this revision.Apr 29 2018, 22:43
dereckson edited the test plan for this revision. (Show Details)
This revision is now accepted and ready to land.Apr 29 2018, 22:43
This revision was automatically updated to reflect the committed changes.