| @@ 1918-1927 (lines=10) @@ | ||
| 1915 | * |
|
| 1916 | * @throws InvalidArgumentException |
|
| 1917 | */ |
|
| 1918 | public static function minCount($array, $min, $message = '') |
|
| 1919 | { |
|
| 1920 | if (\count($array) < $min) { |
|
| 1921 | static::reportInvalidArgument(\sprintf( |
|
| 1922 | $message ?: 'Expected an array to contain at least %2$d elements. Got: %d', |
|
| 1923 | \count($array), |
|
| 1924 | $min |
|
| 1925 | )); |
|
| 1926 | } |
|
| 1927 | } |
|
| 1928 | ||
| 1929 | /** |
|
| 1930 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
|
| @@ 1938-1947 (lines=10) @@ | ||
| 1935 | * |
|
| 1936 | * @throws InvalidArgumentException |
|
| 1937 | */ |
|
| 1938 | public static function maxCount($array, $max, $message = '') |
|
| 1939 | { |
|
| 1940 | if (\count($array) > $max) { |
|
| 1941 | static::reportInvalidArgument(\sprintf( |
|
| 1942 | $message ?: 'Expected an array to contain at most %2$d elements. Got: %d', |
|
| 1943 | \count($array), |
|
| 1944 | $max |
|
| 1945 | )); |
|
| 1946 | } |
|
| 1947 | } |
|
| 1948 | ||
| 1949 | /** |
|
| 1950 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
|
| @@ 1982-1989 (lines=8) @@ | ||
| 1979 | * |
|
| 1980 | * @throws InvalidArgumentException |
|
| 1981 | */ |
|
| 1982 | public static function isList($array, $message = '') |
|
| 1983 | { |
|
| 1984 | if (!\is_array($array) || $array !== \array_values($array)) { |
|
| 1985 | static::reportInvalidArgument( |
|
| 1986 | $message ?: 'Expected list - non-associative array.' |
|
| 1987 | ); |
|
| 1988 | } |
|
| 1989 | } |
|
| 1990 | ||
| 1991 | /** |
|
| 1992 | * @psalm-pure |
|