|
| 1 | +<?php |
| 2 | + |
| 3 | +use PhpTypedValues\Integer\Alias\Id; |
| 4 | +use PhpTypedValues\Integer\Alias\Integer; |
| 5 | +use PhpTypedValues\Integer\Alias\IntType; |
| 6 | +use PhpTypedValues\Integer\Alias\NonNegativeInt; |
| 7 | +use PhpTypedValues\Integer\Alias\PositiveInt; |
| 8 | +use PhpTypedValues\Integer\Alias\TinyInt; |
| 9 | +use PhpTypedValues\Integer\IntegerNonNegative; |
| 10 | +use PhpTypedValues\Integer\IntegerPositive; |
| 11 | +use PhpTypedValues\Integer\IntegerStandard; |
| 12 | +use PhpTypedValues\Integer\IntegerWeekDay; |
| 13 | +use PhpTypedValues\Integer\MariaDb\IntTiny; |
| 14 | + |
| 15 | +/** |
| 16 | + * Integer. |
| 17 | + */ |
| 18 | +testInteger(IntegerStandard::fromInt(10)->value()); |
| 19 | +testPositiveInt(IntegerPositive::fromInt(10)->value()); |
| 20 | +testNonNegativeInt(IntegerNonNegative::fromInt(10)->value()); |
| 21 | +testWeekDayInt(IntegerWeekDay::fromInt(7)->value()); |
| 22 | + |
| 23 | +// DB tinyint usage |
| 24 | +echo TinyInt::fromInt(-5)->toString() . \PHP_EOL; |
| 25 | +echo IntTiny::fromInt(-5)->toString() . \PHP_EOL; |
| 26 | +echo IntTiny::fromString('127')->toString() . \PHP_EOL; |
| 27 | + |
| 28 | +echo NonNegativeInt::fromString('10')->toString() . \PHP_EOL; |
| 29 | +echo PositiveInt::fromString('10')->toString() . \PHP_EOL; |
| 30 | +echo IntegerStandard::fromString('10')->toString() . \PHP_EOL; |
| 31 | +echo Id::fromString('10')->toString() . \PHP_EOL; |
| 32 | +echo IntType::fromString('10')->toString() . \PHP_EOL; |
| 33 | +echo Integer::fromString('10')->toString() . \PHP_EOL; |
| 34 | + |
| 35 | +/** |
| 36 | + * Artificial functions. |
| 37 | + */ |
| 38 | +function testInteger(int $i): int |
| 39 | +{ |
| 40 | + return $i; |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * @param positive-int $i |
| 45 | + */ |
| 46 | +function testPositiveInt(int $i): int |
| 47 | +{ |
| 48 | + return $i; |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * @param non-negative-int $i |
| 53 | + */ |
| 54 | +function testNonNegativeInt(int $i): int |
| 55 | +{ |
| 56 | + return $i; |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * @param int<1, 7> $i |
| 61 | + */ |
| 62 | +function testWeekDayInt(int $i): int |
| 63 | +{ |
| 64 | + return $i; |
| 65 | +} |
0 commit comments