Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

CoordinatesTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 13.33 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 8
loc 60
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A coordinate() 0 8 1
A getCoordinates() 8 8 1
A invalidLatitude() 0 4 1
A getInvalidLatitude() 0 7 1
A invalidLongitude() 0 4 1
A getInvalidLongitude() 0 7 1

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
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Purchase;
6
7
use LauLamanApps\IzettleApi\API\Purchase\Coordinates;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @small
12
 */
13
final class CoordinatesTest extends TestCase
14
{
15
    /**
16
     * @test
17
     * @dataProvider getCoordinates
18
     */
19
    public function coordinate(float $latitude, float $longitude, float $accuracyMeters)
20
    {
21
        $coordinate = new Coordinates($latitude, $longitude, $accuracyMeters);
22
23
        self::assertSame($latitude, $coordinate->getLatitude());
24
        self::assertSame($longitude, $coordinate->getLongitude());
25
        self::assertSame($accuracyMeters, $coordinate->getAccuracyMeters());
26
    }
27
28 View Code Duplication
    public function getCoordinates(): array
29
    {
30
        return [
31
            'Almere Poort, The Netherlands' => [52.3504547, 5.1511458, 10],
32
            'Amsterdam, The Netherlands' => [52.3702157, 4.8951679, 0],
33
            'Den Haag, The Netherlands' => [52.0704978, 4.3006999, -10.1],
34
        ];
35
    }
36
37
    /**
38
     * @test
39
     * @expectedException  \LauLamanApps\IzettleApi\API\Purchase\Exceptions\InvalidLatitudeException
40
     * @dataProvider getInvalidLatitude
41
     */
42
    public function invalidLatitude(float $latitude)
43
    {
44
        new Coordinates($latitude, 5.1511458, 10.0);
45
    }
46
47
    public function getInvalidLatitude(): array
48
    {
49
        return [
50
            [-90.0000001],
51
            [90.0000001],
52
        ];
53
    }
54
55
    /**
56
     * @test
57
     * @expectedException  \LauLamanApps\IzettleApi\API\Purchase\Exceptions\InvalidLongitudeException
58
     * @dataProvider getInvalidLongitude
59
     */
60
    public function invalidLongitude(float $longitude)
61
    {
62
        new Coordinates(52.3504547, $longitude, 10.0);
63
    }
64
65
    public function getInvalidLongitude(): array
66
    {
67
        return [
68
            [-180.0000001],
69
            [180.0000001],
70
        ];
71
    }
72
}
73