Page MenuHomeDevCentral

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

Authored by dereckson on Apr 29 2018, 22:42.
Tags
None
Referenced Files
F2827177: D1632.id4166.diff
Thu, Apr 18, 23:06
Unknown Object (File)
Sun, Apr 14, 22:13
Unknown Object (File)
Tue, Apr 9, 13:21
Unknown Object (File)
Tue, Apr 9, 13:21
Unknown Object (File)
Tue, Apr 9, 10:46
Unknown Object (File)
Mon, Apr 8, 03:01
Unknown Object (File)
Sat, Apr 6, 22:53
Unknown Object (File)
Fri, Apr 5, 12:05
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 Not Applicable
Unit
Tests Not Applicable

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.