| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\GuzzleHttp\Psr7; |
| 5 |
|
| 6 |
/** |
| 7 |
* @internal |
| 8 |
*/ |
| 9 |
final class Integers |
| 10 |
{ |
| 11 |
private function __construct() |
| 12 |
{ |
| 13 |
} |
| 14 |
public static function add(int $a, int $b) : int |
| 15 |
{ |
| 16 |
if ($a < 0 || $b < 0) { |
| 17 |
throw new \InvalidArgumentException('Integer operands must be non-negative'); |
| 18 |
} |
| 19 |
if ($b > \PHP_INT_MAX - $a) { |
| 20 |
throw new \OverflowException('Stream byte count exceeds the maximum integer size supported on this platform'); |
| 21 |
} |
| 22 |
return $a + $b; |
| 23 |
} |
| 24 |
public static function addSigned(int $base, int $delta) : int |
| 25 |
{ |
| 26 |
if ($base < 0) { |
| 27 |
throw new \InvalidArgumentException('Stream offset must be non-negative'); |
| 28 |
} |
| 29 |
if ($delta > 0 && $delta > \PHP_INT_MAX - $base) { |
| 30 |
throw new \OverflowException('Stream offset exceeds the maximum integer size supported on this platform'); |
| 31 |
} |
| 32 |
$value = $base + $delta; |
| 33 |
if ($value < 0) { |
| 34 |
// A negative computed offset is a seek failure at runtime, so throw |
| 35 |
// RuntimeException per PSR-7, unlike the precondition check above. |
| 36 |
throw new \RuntimeException('Stream offset must be non-negative'); |
| 37 |
} |
| 38 |
return $value; |
| 39 |
} |
| 40 |
/** |
| 41 |
* @param mixed $value |
| 42 |
*/ |
| 43 |
public static function assertEngineInteger($value, string $what) : ?int |
| 44 |
{ |
| 45 |
if ($value === \false || $value === null) { |
| 46 |
return null; |
| 47 |
} |
| 48 |
if (!\is_int($value) || $value < 0) { |
| 49 |
throw new \OverflowException($what . ' exceeds the maximum integer size supported on this platform'); |
| 50 |
} |
| 51 |
return $value; |
| 52 |
} |
| 53 |
/** |
| 54 |
* @param mixed $value |
| 55 |
*/ |
| 56 |
public static function assertOptionalNonNegativeSize($value, string $name) : ?int |
| 57 |
{ |
| 58 |
if ($value === null) { |
| 59 |
return null; |
| 60 |
} |
| 61 |
if (!\is_int($value) || $value < 0) { |
| 62 |
throw new \InvalidArgumentException($name . ' must be a non-negative integer or null'); |
| 63 |
} |
| 64 |
return $value; |
| 65 |
} |
| 66 |
/** |
| 67 |
* @param mixed $value |
| 68 |
*/ |
| 69 |
public static function assertNonNegativeInteger($value, string $name) : int |
| 70 |
{ |
| 71 |
if (!\is_int($value) || $value < 0) { |
| 72 |
throw new \InvalidArgumentException($name . ' must be a non-negative integer'); |
| 73 |
} |
| 74 |
return $value; |
| 75 |
} |
| 76 |
/** |
| 77 |
* @param mixed $value |
| 78 |
*/ |
| 79 |
public static function assertLimitInteger($value, string $name) : int |
| 80 |
{ |
| 81 |
if (!\is_int($value) || $value < -1) { |
| 82 |
throw new \InvalidArgumentException($name . ' must be -1 or a non-negative integer'); |
| 83 |
} |
| 84 |
return $value; |
| 85 |
} |
| 86 |
} |
| 87 |
|