Completed
Push — master ( 5dfd0e...1b0014 )
by Tobias
02:15
created

Assert::notNull()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 2
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
class Assert
16
{
17
    /**
18
     * @param float  $value
19
     * @param string $message
20
     */
21 View Code Duplication
    public static function latitude($value, $message = '')
0 ignored issues
show
Duplication introduced by
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.

Loading history...
22
    {
23
        if (!is_float($value)) {
24
            throw new \InvalidArgumentException(
25
                sprintf($message ?: 'Expected a double. Got: %s', self::typeToString($value))
26
            );
27
        }
28
29
        if ($value < -90 || $value > 90) {
30
            throw new \InvalidArgumentException(
31
                sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
32
            );
33
        }
34
    }
35
36
    /**
37
     * @param float  $value
38
     * @param string $message
39
     */
40 View Code Duplication
    public static function longitude($value, $message = '')
0 ignored issues
show
Duplication introduced by
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.

Loading history...
41
    {
42
        if (!is_float($value)) {
43
            throw new \InvalidArgumentException(
44
                sprintf($message ?: 'Expected a doable. Got: %s', self::typeToString($value))
45
            );
46
        }
47
48
        if ($value < -180 || $value > 180) {
49
            throw new \InvalidArgumentException(
50
                sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
51
            );
52
        }
53
    }
54
55
    /**
56
     * @param mixed  $value
57
     * @param string $message
58
     */
59
    public static function notNull($value, $message = '')
60
    {
61
        if (null === $value) {
62
            throw new \InvalidArgumentException(sprintf($message ?: 'Value cannot be null'));
63
        }
64
    }
65
66
    private static function typeToString($value)
67
    {
68
        return is_object($value) ? get_class($value) : gettype($value);
69
    }
70
}
71