Skip to content
Permalink
Browse files

Validators: added support for `?nullable` types

  • Loading branch information...
dg committed Mar 12, 2019
1 parent 7a9587b commit 2f751f14a675cee06552467e1ab144cec3cb72dd
Showing with 13 additions and 0 deletions.
  1. +5 −0 src/Utils/Validators.php
  2. +8 −0 tests/Utils/Validators.is().phpt
@@ -124,6 +124,11 @@ public static function is($value, string $expected): bool
return true;
}
continue;
} elseif (substr($item, 0, 1) === '?') {
$item = substr($item, 1);
if ($value === null) {
return true;
}
}
[$type] = $item = explode(':', $item, 2);
@@ -373,3 +373,11 @@ test(function () {
Assert::true(Validators::is([['ABCD', 'EFGH'], ['IJKL']], 'string:4[][]'));
Assert::false(Validators::is([['ABCD', 'EFGH'], ['IJKLM']], 'string:4[][]'));
});
test(function () {
Assert::true(Validators::is(null, '?string'));
Assert::true(Validators::is('1', '?string'));
Assert::false(Validators::is(true, '?int'));
Assert::false(Validators::is(0, '?string'));
});

0 comments on commit 2f751f1

Please sign in to comment.
You can’t perform that action at this time.