-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename "IterableType" into "IterableVal"
When we created this rule in version 1.0 in 2015, PHP was in version 5.6, and the `is_iterable()` function didn't exist. Only in version 7.1, released at the end of 2016, was the pseudo-type "iterable" introduced to PHP. This old "IterableType" rule is almost obsolete. Still, I decided to keep it because it is possible to use foreach in any object, as it will iterate over its public properties. I did rename the rule because that makes more sense. An "IterableType" rule should guarantee that the input type is the real-(pseudo)-iterable. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
471e147
commit 980ab28
Showing
14 changed files
with
76 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# IterableVal | ||
|
||
- `IterableVal()` | ||
|
||
Validates whether the input is an iterable value, in other words, if you can iterate over it with the [foreach][] language construct. | ||
|
||
```php | ||
v::iterableVal()->validate([]); // true | ||
v::iterableVal()->validate(new ArrayObject()); // true | ||
v::iterableVal()->validate(new stdClass()); // true | ||
v::iterableVal()->validate('string'); // false | ||
``` | ||
|
||
## Note | ||
|
||
This rule doesn't behave as PHP's [is_iterable() function because it considers that you can iterate over any object. | ||
|
||
## Categorization | ||
|
||
- Types | ||
|
||
## Changelog | ||
|
||
| Version | Description | | ||
|---------:|----------------------------------------------| | ||
| 3.0.0 | Renamed from `IterableType` to `IterableVal` | | ||
| 1.0.8 | Renamed from `Iterable` to `IterableType` | | ||
| 1.0.0 | Created as `Iterable` | | ||
|
||
*** | ||
See also: | ||
|
||
- [ArrayType](ArrayType.md) | ||
- [ArrayVal](ArrayVal.md) | ||
- [Countable](Countable.md) | ||
- [Each](Each.md) | ||
- [Instance](Instance.md) | ||
|
||
[is_iterable()]: https://www.php.net/is_iterable | ||
[foreach]: http://php.net/foreach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--FILE-- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Validator as v; | ||
|
||
exceptionMessage(static fn() => v::iterableVal()->check(3)); | ||
exceptionMessage(static fn() => v::not(v::iterableVal())->check([2, 3])); | ||
exceptionFullMessage(static fn() => v::iterableVal()->assert('String')); | ||
exceptionFullMessage(static fn() => v::not(v::iterableVal())->assert(new stdClass())); | ||
?> | ||
--EXPECT-- | ||
3 must be iterable | ||
`[2, 3]` must not be iterable | ||
- "String" must be iterable | ||
- `stdClass {}` must not be iterable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters