@@ -20,53 +20,52 @@ class Assert
2020 * @param float $value
2121 * @param string $message
2222 */
23- public static function latitude ($ value , $ message = '' )
23+ public static function latitude ($ value , string $ message = '' )
2424 {
25- if (!is_float ($ value )) {
26- throw new InvalidArgument (
27- sprintf ($ message ?: 'Expected a double. Got: %s ' , self ::typeToString ($ value ))
28- );
29- }
30-
25+ self ::float ($ value , $ message );
3126 if ($ value < -90 || $ value > 90 ) {
32- throw new InvalidArgument (
33- sprintf ($ message ?: 'Latitude should be between -90 and 90. Got: %s ' , $ value )
34- );
27+ throw new InvalidArgument (sprintf ($ message ?: 'Latitude should be between -90 and 90. Got: %s ' , $ value ));
3528 }
3629 }
3730
3831 /**
3932 * @param float $value
4033 * @param string $message
4134 */
42- public static function longitude ($ value , $ message = '' )
35+ public static function longitude ($ value , string $ message = '' )
4336 {
44- if (!is_float ($ value )) {
45- throw new InvalidArgument (
46- sprintf ($ message ?: 'Expected a doable. Got: %s ' , self ::typeToString ($ value ))
47- );
48- }
49-
37+ self ::float ($ value , $ message );
5038 if ($ value < -180 || $ value > 180 ) {
51- throw new InvalidArgument (
52- sprintf ($ message ?: 'Latitude should be between -90 and 90. Got: %s ' , $ value )
53- );
39+ throw new InvalidArgument (sprintf ($ message ?: 'Longitude should be between -180 and 180. Got: %s ' , $ value ));
5440 }
5541 }
5642
5743 /**
5844 * @param mixed $value
5945 * @param string $message
6046 */
61- public static function notNull ($ value , $ message = '' )
47+ public static function notNull ($ value , string $ message = '' )
6248 {
6349 if (null === $ value ) {
6450 throw new InvalidArgument (sprintf ($ message ?: 'Value cannot be null ' ));
6551 }
6652 }
6753
68- private static function typeToString ($ value )
54+ private static function typeToString ($ value ): string
6955 {
7056 return is_object ($ value ) ? get_class ($ value ) : gettype ($ value );
7157 }
58+
59+ /**
60+ * @param $value
61+ * @param $message
62+ */
63+ private static function float ($ value , string $ message )
64+ {
65+ if (!is_float ($ value )) {
66+ throw new InvalidArgument (
67+ sprintf ($ message ?: 'Expected a float. Got: %s ' , self ::typeToString ($ value ))
68+ );
69+ }
70+ }
7271}
0 commit comments