These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Geocoder package. |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @license MIT License |
||
11 | */ |
||
12 | |||
13 | namespace Geocoder; |
||
14 | |||
15 | use Geocoder\Exception\InvalidArgument; |
||
16 | |||
17 | class Assert |
||
18 | { |
||
19 | /** |
||
20 | * @param float $value |
||
21 | * @param string $message |
||
22 | */ |
||
23 | 17 | View Code Duplication | public static function latitude($value, string $message = '') |
0 ignored issues
–
show
|
|||
24 | { |
||
25 | 17 | self::float($value, $message); |
|
26 | 17 | if ($value < -90 || $value > 90) { |
|
27 | throw new InvalidArgument(sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)); |
||
28 | } |
||
29 | 17 | } |
|
30 | |||
31 | /** |
||
32 | * @param float $value |
||
33 | * @param string $message |
||
34 | */ |
||
35 | 17 | View Code Duplication | public static function longitude($value, string $message = '') |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
36 | { |
||
37 | 17 | self::float($value, $message); |
|
38 | 17 | if ($value < -180 || $value > 180) { |
|
39 | throw new InvalidArgument(sprintf($message ?: 'Longitude should be between -180 and 180. Got: %s', $value)); |
||
40 | } |
||
41 | 17 | } |
|
42 | |||
43 | /** |
||
44 | * @param mixed $value |
||
45 | * @param string $message |
||
46 | */ |
||
47 | 17 | public static function notNull($value, string $message = '') |
|
48 | { |
||
49 | 17 | if (null === $value) { |
|
50 | throw new InvalidArgument(sprintf($message ?: 'Value cannot be null')); |
||
51 | } |
||
52 | 17 | } |
|
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 | 17 | private static function float($value, string $message) |
|
64 | { |
||
65 | 17 | if (!is_float($value)) { |
|
66 | throw new InvalidArgument( |
||
67 | sprintf($message ?: 'Expected a float. Got: %s', self::typeToString($value)) |
||
68 | ); |
||
69 | } |
||
70 | 17 | } |
|
71 | } |
||
72 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.