diff --git a/docs/ArrayType.md b/docs/ArrayType.md index 001fbbcf..ed72eb39 100644 --- a/docs/ArrayType.md +++ b/docs/ArrayType.md @@ -19,7 +19,7 @@ See also: * [Countable](Countable.md) * [FloatType](FloatType.md) * [IntType](IntType.md) - * [Iterable](Iterable.md) + * [IterableType](IterableType.md) * [NullType](NullType.md) * [ObjectType](ObjectType.md) * [ResourceType](ResourceType.md) diff --git a/docs/ArrayVal.md b/docs/ArrayVal.md index eb246a13..ec9eaf06 100644 --- a/docs/ArrayVal.md +++ b/docs/ArrayVal.md @@ -16,7 +16,7 @@ See also: * [ArrayType](ArrayType.md) * [Countable](Countable.md) * [Each](Each.md) - * [Iterable](Iterable.md) + * [IterableType](IterableType.md) * [Key](Key.md) * [KeySet](KeySet.md) * [KeyValue](KeyValue.md) diff --git a/docs/Countable.md b/docs/Countable.md index 2bbe152a..0353de4d 100644 --- a/docs/Countable.md +++ b/docs/Countable.md @@ -16,4 +16,4 @@ See also: * [ArrayVal](ArrayVal.md) * [Instance](Instance.md) - * [Iterable](Iterable.md) + * [IterableType](IterableType.md) diff --git a/docs/Iterable.md b/docs/Iterable.md index 1b1c01a5..b64abe28 100644 --- a/docs/Iterable.md +++ b/docs/Iterable.md @@ -2,19 +2,4 @@ - `v::iterable()` -Validates if the input is iterable, in other words, if you're able to iterate -over it with [foreach](http://php.net/foreach) language construct. - -```php -v::iterable()->validate([]); // true -v::iterable()->validate(new ArrayObject()); // true -v::iterable()->validate(new stdClass()); // true -v::iterable()->validate('string'); // false -``` - -*** -See also: - - * [ArrayVal](ArrayVal.md) - * [Countable](Countable.md) - * [Instance](Instance.md) +**Deprecated**: Use [IterableType](IterableType.md) instead. diff --git a/docs/IterableType.md b/docs/IterableType.md new file mode 100644 index 00000000..a246af27 --- /dev/null +++ b/docs/IterableType.md @@ -0,0 +1,20 @@ +# IterableType + +- `v::iterableType()` + +Validates if the input is iterable, in other words, if you're able to iterate +over it with [foreach](http://php.net/foreach) language construct. + +```php +v::iterableType()->validate([]); // true +v::iterableType()->validate(new ArrayObject()); // true +v::iterableType()->validate(new stdClass()); // true +v::iterableType()->validate('string'); // false +``` + +*** +See also: + + * [ArrayVal](ArrayVal.md) + * [Countable](Countable.md) + * [Instance](Instance.md) diff --git a/docs/VALIDATORS.md b/docs/VALIDATORS.md index ebb7f53e..599d28bd 100644 --- a/docs/VALIDATORS.md +++ b/docs/VALIDATORS.md @@ -15,7 +15,7 @@ * [Instance](Instance.md) * [IntVal](IntVal.md) * [IntType](IntType.md) - * [Iterable](Iterable.md) + * [IterableType](IterableType.md) * [NullType](NullType.md) * [Numeric](Numeric.md) * [ObjectType](ObjectType.md) @@ -250,7 +250,7 @@ * [IntVal](IntVal.md) * [IntType](IntType.md) * [Ip](Ip.md) - * [Iterable](Iterable.md) + * [IterableType](IterableType.md) * [Json](Json.md) * [Key](Key.md) * [KeyNested](KeyNested.md) diff --git a/library/Exceptions/IterableException.php b/library/Exceptions/IterableException.php index 52a58c6a..67542d56 100644 --- a/library/Exceptions/IterableException.php +++ b/library/Exceptions/IterableException.php @@ -11,14 +11,5 @@ namespace Respect\Validation\Exceptions; -class IterableException extends ValidationException -{ - public static $defaultTemplates = [ - self::MODE_DEFAULT => [ - self::STANDARD => '{{name}} must be iterable', - ], - self::MODE_NEGATIVE => [ - self::STANDARD => '{{name}} must not be iterable', - ], - ]; -} +class IterableException extends IterableTypeException +{} diff --git a/library/Exceptions/IterableTypeException.php b/library/Exceptions/IterableTypeException.php new file mode 100644 index 00000000..94bb7bec --- /dev/null +++ b/library/Exceptions/IterableTypeException.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Exceptions; + +class IterableTypeException extends ValidationException +{ + public static $defaultTemplates = [ + self::MODE_DEFAULT => [ + self::STANDARD => '{{name}} must be iterable', + ], + self::MODE_NEGATIVE => [ + self::STANDARD => '{{name}} must not be iterable', + ], + ]; +} diff --git a/library/Rules/Each.php b/library/Rules/Each.php index 155eff37..dc24b31f 100644 --- a/library/Rules/Each.php +++ b/library/Rules/Each.php @@ -14,7 +14,7 @@ namespace Respect\Validation\Rules; use Respect\Validation\Exceptions\ValidationException; use Respect\Validation\Validatable; -class Each extends Iterable +class Each extends IterableType { public $itemValidator; public $keyValidator; diff --git a/library/Rules/Iterable.php b/library/Rules/Iterable.php index bbc33799..6633f952 100644 --- a/library/Rules/Iterable.php +++ b/library/Rules/Iterable.php @@ -9,14 +9,6 @@ * file that was distributed with this source code. */ -namespace Respect\Validation\Rules; - -class Iterable extends AbstractRule -{ - public function validate($input) - { - return is_array($input) || - $input instanceof \stdClass || - $input instanceof \Traversable; - } +if (version_compare(PHP_VERSION, '7.1', '<')) { + eval('namespace Respect\Validation\Rules; class Iterable extends IterableType {}'); } diff --git a/library/Rules/IterableType.php b/library/Rules/IterableType.php new file mode 100644 index 00000000..d6a7f4db --- /dev/null +++ b/library/Rules/IterableType.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Rules; + +class IterableType extends AbstractRule +{ + public function validate($input) + { + return is_array($input) || + $input instanceof \stdClass || + $input instanceof \Traversable; + } +} diff --git a/tests/integration/rules/iterable_1.phpt b/tests/integration/rules/iterableType_1.phpt similarity index 55% rename from tests/integration/rules/iterable_1.phpt rename to tests/integration/rules/iterableType_1.phpt index 83684af6..8a83e348 100644 --- a/tests/integration/rules/iterable_1.phpt +++ b/tests/integration/rules/iterableType_1.phpt @@ -5,7 +5,7 @@ require 'vendor/autoload.php'; use Respect\Validation\Validator as v; -v::iterable()->assert([1, 2, 3]); -v::iterable()->check(new ArrayObject()); +v::iterableType()->assert([1, 2, 3]); +v::iterableType()->check(new ArrayObject()); ?> --EXPECTF-- diff --git a/tests/integration/rules/iterable_2.phpt b/tests/integration/rules/iterableType_2.phpt similarity index 55% rename from tests/integration/rules/iterable_2.phpt rename to tests/integration/rules/iterableType_2.phpt index 8986cec7..ec799394 100644 --- a/tests/integration/rules/iterable_2.phpt +++ b/tests/integration/rules/iterableType_2.phpt @@ -3,12 +3,12 @@ require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IterableException; +use Respect\Validation\Exceptions\IterableTypeException; use Respect\Validation\Validator as v; try { - v::iterable()->check(3); -} catch (IterableException $exception) { + v::iterableType()->check(3); +} catch (IterableTypeException $exception) { echo $exception->getMainMessage(); } ?> diff --git a/tests/integration/rules/iterable_3.phpt b/tests/integration/rules/iterableType_3.phpt similarity index 54% rename from tests/integration/rules/iterable_3.phpt rename to tests/integration/rules/iterableType_3.phpt index d936c7b6..6b098fd7 100644 --- a/tests/integration/rules/iterable_3.phpt +++ b/tests/integration/rules/iterableType_3.phpt @@ -3,12 +3,12 @@ require 'vendor/autoload.php'; -use Respect\Validation\Exceptions\IterableException; +use Respect\Validation\Exceptions\IterableTypeException; use Respect\Validation\Validator as v; try { - v::not(v::iterable())->check([2, 3]); -} catch (IterableException $exception) { + v::not(v::iterableType())->check([2, 3]); +} catch (IterableTypeException $exception) { echo $exception->getMainMessage(); } ?> diff --git a/tests/integration/rules/iterable_4.phpt b/tests/integration/rules/iterableType_4.phpt similarity index 86% rename from tests/integration/rules/iterable_4.phpt rename to tests/integration/rules/iterableType_4.phpt index d3ce5fa6..4da5c4c1 100644 --- a/tests/integration/rules/iterable_4.phpt +++ b/tests/integration/rules/iterableType_4.phpt @@ -6,7 +6,7 @@ use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; try { - v::iterable()->assert('String'); + v::iterableType()->assert('String'); } catch (AllOfException $exception) { echo $exception->getFullMessage(); } diff --git a/tests/integration/rules/iterable_5.phpt b/tests/integration/rules/iterableType_5.phpt similarity index 83% rename from tests/integration/rules/iterable_5.phpt rename to tests/integration/rules/iterableType_5.phpt index fb8fecf8..37d2fd5f 100644 --- a/tests/integration/rules/iterable_5.phpt +++ b/tests/integration/rules/iterableType_5.phpt @@ -6,7 +6,7 @@ use Respect\Validation\Exceptions\AllOfException; use Respect\Validation\Validator as v; try { - v::not(v::iterable())->assert(new stdClass()); + v::not(v::iterableType())->assert(new stdClass()); } catch (AllOfException $exception) { echo $exception->getFullMessage(); } diff --git a/tests/unit/Exceptions/CheckExceptionsTest.php b/tests/unit/Exceptions/CheckExceptionsTest.php index 8dcfb223..1169c343 100644 --- a/tests/unit/Exceptions/CheckExceptionsTest.php +++ b/tests/unit/Exceptions/CheckExceptionsTest.php @@ -16,7 +16,7 @@ use ReflectionClass; class CheckExceptionsTest extends \PHPUnit_Framework_TestCase { - protected $deprecateds = []; + protected $deprecateds = ['Iterable']; public function provideListOfRuleNames() { diff --git a/tests/unit/Rules/IterableTest.php b/tests/unit/Rules/IterableTypeTest.php similarity index 86% rename from tests/unit/Rules/IterableTest.php rename to tests/unit/Rules/IterableTypeTest.php index fcf26276..13d711f6 100644 --- a/tests/unit/Rules/IterableTest.php +++ b/tests/unit/Rules/IterableTypeTest.php @@ -13,13 +13,13 @@ namespace Respect\Validation\Rules; /** * @group rule - * @covers Respect\Validation\Rules\Iterable + * @covers Respect\Validation\Rules\IterableType */ class IterableTest extends RuleTestCase { public function providerForValidInput() { - $rule = new Iterable(); + $rule = new IterableType(); return [ [$rule, [1, 2, 3]], @@ -30,7 +30,7 @@ class IterableTest extends RuleTestCase public function providerForInvalidInput() { - $rule = new Iterable(); + $rule = new IterableType(); return [ [$rule, 3],