Skip to content

Commit 8bd068b

Browse files
author
Kirill Nesmeyanov
committed
Fix tests
1 parent 0e744d4 commit 8bd068b

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

src/Type/ArrayKeyType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ public function cast(mixed $value, Context $context): string|int
4545

4646
if (\is_float($value)) {
4747
try {
48+
/** @var int */
4849
return $this->int->cast($value, $context);
4950
} catch (ValueExceptionInterface) {
51+
/** @var string */
5052
return $this->string->cast($value, $context);
5153
}
5254
}
5355

5456
if (!$context->isStrictTypesEnabled()) {
57+
/** @var string */
5558
return $this->string->cast($value, $context);
5659
}
5760

src/Type/IntType.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,13 @@ class IntType implements TypeInterface
1111
{
1212
public function match(mixed $value, Context $context): bool
1313
{
14-
return \is_int($value)
15-
// Assert for unary minus operation that overflows min int value.
16-
//
17-
// This is what happens:
18-
// 1) 9223372036854775808 is parsed by the PHP and converted
19-
// to float(9.2233720368548E+18) on overflow.
20-
// 2) The unary minus ("-") operator is applied to the
21-
// float(9.2233720368548E+18), yielding float(-9.2233720368548E+18)
22-
// as the output.
23-
//
24-
// The set of specified operations compares negative floats
25-
// (after the operations performed) with the input float value.
26-
//
27-
// @phpstan-ignore-next-line : Support for PHP x86 implicit int conversion
28-
|| $value === -2147483648
29-
// @phpstan-ignore-next-line : Support for PHP x64 implicit int conversion
30-
|| $value === -9223372036854775808;
14+
return \is_int($value);
3115
}
3216

3317
public function cast(mixed $value, Context $context): int
3418
{
3519
return match (true) {
3620
\is_int($value) => $value,
37-
// @phpstan-ignore-next-line : In case of PHP x86 the value will be casted to float
38-
$value === -2147483648,
39-
$value === -9223372036854775808 => \PHP_INT_MIN,
4021
!$context->isStrictTypesEnabled() => $this->convertToInt($value, $context),
4122
default => throw InvalidValueException::createFromContext(
4223
value: $value,

tests/Feature/Type/int.feature

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Feature: Checking the "int" (TypeLang\Mapper\Type\IntType) type behavior
1111
Examples:
1212
| value | is_matched |
1313
| 9223372036854775807 | true |
14+
| -9223372036854775807 | true |
1415
| -9223372036854775807-1 | true |
15-
| -9223372036854775808 | true |
16+
| -9223372036854775808 | false |
17+
| -9223372036854775809 | false |
1618
| 1 | true |
1719
| 0 | true |
1820
| -1 | true |
@@ -50,8 +52,10 @@ Feature: Checking the "int" (TypeLang\Mapper\Type\IntType) type behavior
5052
Examples:
5153
| value | result |
5254
| 9223372036854775807 | 9223372036854775807 |
55+
| -9223372036854775807 | -9223372036854775807 |
5356
| -9223372036854775807-1 | -9223372036854775807-1 |
5457
| -9223372036854775808 | -9223372036854775807-1 |
58+
| -9223372036854775809 | -9223372036854775807-1 |
5559
| 1 | 1 |
5660
| 0 | 0 |
5761
| -1 | -1 |
@@ -93,8 +97,10 @@ Feature: Checking the "int" (TypeLang\Mapper\Type\IntType) type behavior
9397
Examples:
9498
| value | result |
9599
| 9223372036854775807 | 9223372036854775807 |
100+
| -9223372036854775807 | -9223372036854775807 |
96101
| -9223372036854775807-1 | -9223372036854775807-1 |
97-
| -9223372036854775808 | -9223372036854775807-1 |
102+
| -9223372036854775808 | <error: Passed value -9.2233720368548E+18 is invalid> |
103+
| -9223372036854775809 | <error: Passed value -9.2233720368548E+18 is invalid> |
98104
| 1 | 1 |
99105
| 0 | 0 |
100106
| -1 | -1 |

0 commit comments

Comments
 (0)