XMLWordPrintable

    Details

    • Type: Language-Specification
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      The count of an array or Countable is always ">=0", so update this test to either "==0" or ">0".
    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity

      Description

      The count of elements from an array or Countable object is always greater than or equal to zero. So testing that the count is greater than or equal to zero doesn't make sense, since the result is always true. Similarly testing that it is less than zero will always return false. Perhaps the intent was to check the non-emptiness of the object or array instead.

      Noncompliant Code Example

      if (count($arr) >= 0) { ... }
      
      if (count($arr) < 0) { ... }
      
      $result = count($arr) >= 0;
      
      if (0 > count($arr)) { ... }
      

      Compliant Solution

      if (count($arr) != 0) { ... }
      
      if (count($arr) > 0) { ... }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            michael.gumowski Michael Gumowski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: