Completed
Push — master ( 823f02...da35d1 )
by Tobias
03:18
created

Assert   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 56
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 17
lcom 0
cbo 1
dl 28
loc 56
ccs 11
cts 22
cp 0.5
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B latitude() 14 14 6
B longitude() 14 14 6
A notNull() 0 6 3
A typeToString() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 15 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...
24
    {
25 15
        if (!is_float($value)) {
26
            throw new InvalidArgument(
27
                sprintf($message ?: 'Expected a double. Got: %s', self::typeToString($value))
28
            );
29
        }
30
31 15
        if ($value < -90 || $value > 90) {
32
            throw new InvalidArgument(
33
                sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
34
            );
35
        }
36 15
    }
37
38
    /**
39
     * @param float  $value
40
     * @param string $message
41
     */
42 15 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...
43
    {
44 15
        if (!is_float($value)) {
45
            throw new InvalidArgument(
46
                sprintf($message ?: 'Expected a doable. Got: %s', self::typeToString($value))
47
            );
48
        }
49
50 15
        if ($value < -180 || $value > 180) {
51
            throw new InvalidArgument(
52
                sprintf($message ?: 'Latitude should be between -90 and 90. Got: %s', $value)
53
            );
54
        }
55 15
    }
56
57
    /**
58
     * @param mixed  $value
59
     * @param string $message
60
     */
61 15
    public static function notNull($value, $message = '')
62
    {
63 15
        if (null === $value) {
64
            throw new InvalidArgument(sprintf($message ?: 'Value cannot be null'));
65
        }
66 15
    }
67
68
    private static function typeToString($value)
69
    {
70
        return is_object($value) ? get_class($value) : gettype($value);
71
    }
72
}
73