| @@ 1961-1970 (lines=10) @@ | ||
| 1958 | * |
|
| 1959 | * @throws InvalidArgumentException |
|
| 1960 | */ |
|
| 1961 | public static function minCount($array, $min, $message = '') |
|
| 1962 | { |
|
| 1963 | if (\count($array) < $min) { |
|
| 1964 | static::reportInvalidArgument(\sprintf( |
|
| 1965 | $message ?: 'Expected an array to contain at least %2$d elements. Got: %d', |
|
| 1966 | \count($array), |
|
| 1967 | $min |
|
| 1968 | )); |
|
| 1969 | } |
|
| 1970 | } |
|
| 1971 | ||
| 1972 | /** |
|
| 1973 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
|
| @@ 1981-1990 (lines=10) @@ | ||
| 1978 | * |
|
| 1979 | * @throws InvalidArgumentException |
|
| 1980 | */ |
|
| 1981 | public static function maxCount($array, $max, $message = '') |
|
| 1982 | { |
|
| 1983 | if (\count($array) > $max) { |
|
| 1984 | static::reportInvalidArgument(\sprintf( |
|
| 1985 | $message ?: 'Expected an array to contain at most %2$d elements. Got: %d', |
|
| 1986 | \count($array), |
|
| 1987 | $max |
|
| 1988 | )); |
|
| 1989 | } |
|
| 1990 | } |
|
| 1991 | ||
| 1992 | /** |
|
| 1993 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
|
| @@ 2025-2032 (lines=8) @@ | ||
| 2022 | * |
|
| 2023 | * @throws InvalidArgumentException |
|
| 2024 | */ |
|
| 2025 | public static function isList($array, $message = '') |
|
| 2026 | { |
|
| 2027 | if (!\is_array($array) || $array !== \array_values($array)) { |
|
| 2028 | static::reportInvalidArgument( |
|
| 2029 | $message ?: 'Expected list - non-associative array.' |
|
| 2030 | ); |
|
| 2031 | } |
|
| 2032 | } |
|
| 2033 | ||
| 2034 | /** |
|
| 2035 | * @psalm-pure |
|