Something I've seen in code is the unclear use of zero when adding limits, such as loading items from a database.
In some instances, setting zero will return all items - essentially, an 'unlimited' value in disguise - rather than returning no results, which is what I'd expect.
throw new InvalidArgumentException('A limit must be a positive integer.');
}
$query->range(0, $limit);
}
```
If the limit is not an integer, nothing happens.
It throws an Exception if the value is invalid - i.e. less than one.
The limit is applied if the limit is greater than or equal to one.
While it's more complex as there are more checks to perform and different types in use, I think this is clearer and easier for someone reading or implementing the code to understand what it does and use it correctly.