Page MenuHomeDevCentral

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

Authored by dereckson on Apr 29 2018, 22:42.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 16, 02:25
Unknown Object (File)
Wed, Nov 13, 07:30
Unknown Object (File)
Mon, Nov 11, 05:26
Unknown Object (File)
Sun, Nov 10, 20:49
Unknown Object (File)
Sun, Nov 10, 20:25
Unknown Object (File)
Sun, Nov 10, 17:52
Unknown Object (File)
Sun, Nov 10, 17:51
Unknown Object (File)
Sun, Nov 10, 17:39
Subscribers
None

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
Lint Passed
Unit
Tests Passed
Branch
TraversableUtils
Build Status
Buildable 2559
Build 2807: arc lint + arc unit

Event Timeline

dereckson created this revision.
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.