123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare(strict_types=1);
- namespace Geocoder;
- use Geocoder\Exception\InvalidArgument;
- class Assert
- {
-
- public static function latitude($value, string $message = '')
- {
- self::float($value, $message);
- if ($value < -90 || $value > 90) {
- throw new InvalidArgument(sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value));
- }
- }
-
- public static function longitude($value, string $message = '')
- {
- self::float($value, $message);
- if ($value < -180 || $value > 180) {
- throw new InvalidArgument(sprintf($message ?: 'Longitude should be between -180 and 180. Got: %s', $value));
- }
- }
-
- public static function notNull($value, string $message = '')
- {
- if (null === $value) {
- throw new InvalidArgument(sprintf($message ?: 'Value cannot be null'));
- }
- }
- private static function typeToString($value): string
- {
- return is_object($value) ? get_class($value) : gettype($value);
- }
-
- private static function float($value, string $message)
- {
- if (!is_float($value)) {
- throw new InvalidArgument(sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value)));
- }
- }
- }
|