Browse Source

Cleaning up method

Jose Lorenzo Rodriguez 10 years ago
parent
commit
96416bcf68
2 changed files with 6 additions and 8 deletions
  1. 5 7
      src/Validation/Validation.php
  2. 1 1
      tests/TestCase/Validation/ValidationTest.php

+ 5 - 7
src/Validation/Validation.php

@@ -216,23 +216,21 @@ class Validation
     }
 
     /**
-     * Used to check the count of a given value of type string, int, or array.
+     * Used to check the count of a given value of type array or Countable.
      *
-     * If a string value is passed the string length is used as count.
-     *
-     * @param array|int|string $check1 The value to check the count on.
+     * @param array|\Countable $check The value to check the count on.
      * @param string $operator Can be either a word or operand
      *    is greater >, is less <, greater or equal >=
      *    less or equal <=, is less <, equal to ==, not equal !=
      * @param int $expectedCount The expected count value.
      * @return bool Success
      */
-    public static function numElements($check1, $operator, $expectedCount)
+    public static function numElements($check, $operator, $expectedCount)
     {
-        if (!is_array($check1) || $check1 instanceof \Countable) {
+        if (!is_array($check) && !$check instanceof \Countable) {
             return false;
         }
-        return self::comparison(count($check1), $operator, $expectedCount);
+        return self::comparison(count($check), $operator, $expectedCount);
     }
 
     /**

+ 1 - 1
tests/TestCase/Validation/ValidationTest.php

@@ -2775,7 +2775,7 @@ class ValidationTest extends TestCase
         $this->assertFalse(Validation::numElements($array, '>', 3));
         $this->assertFalse(Validation::numElements($array, '<', 1));
 
-        $callable = function() {
+        $callable = function () {
             return '';
         };