Tuple validation
rudiedirkx opened this issue · comments
Rudie Dirkx commented
I know a tuple isn't a PHP structure, but you can still format and validate your data like it is. For instance, I want to validate a list of tuples:
[
[date, date, [ints], int],
[date, date, [ints], int],
[date, date, [ints], int],
// etc, 20 or 100 more lines, so I don't want assoc arrays (Expect::structure())
]
The outside would be a listOf()
, but a list of what? Tuples. Numeric arrays with a set amount of items that have specific types: elements 0 and 1 are dates, element 2 is a listOf(int())
, element 3 is an int()
.
Maybe something like
$schema = Expect::listOf(Expect::tuple(
Custom::date(),
Custom::date(),
Expect::listOf(Expect::int()),
Expect::int(),
));
Rudie Dirkx commented
We can use Expect::structure()
with numeric keys for that 👍