| 1 | <?php |
||
| 17 | class Assert |
||
|
|
|||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param float $value |
||
| 21 | * @param string $message |
||
| 22 | */ |
||
| 23 | public static function latitude($value, string $message = '') |
||
| 24 | { |
||
| 25 | self::float($value, $message); |
||
| 26 | if ($value < -90 || $value > 90) { |
||
| 27 | throw new InvalidArgument(sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param float $value |
||
| 33 | * @param string $message |
||
| 34 | */ |
||
| 35 | public static function longitude($value, string $message = '') |
||
| 36 | { |
||
| 37 | self::float($value, $message); |
||
| 38 | if ($value < -180 || $value > 180) { |
||
| 39 | throw new InvalidArgument(sprintf($message ?: 'Longitude should be between -180 and 180. Got: %s', $value)); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param mixed $value |
||
| 45 | * @param string $message |
||
| 46 | */ |
||
| 47 | public static function notNull($value, string $message = '') |
||
| 53 | |||
| 54 | private static function typeToString($value): string |
||
| 55 | { |
||
| 56 | return is_object($value) ? get_class($value) : gettype($value); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param $value |
||
| 61 | * @param $message |
||
| 62 | */ |
||
| 63 | private static function float($value, string $message) |
||
| 71 | } |
||
| 72 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.