Completed
Pull Request — master (#11)
by Laurens
01:56
created

CoordinatesBuilderTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 16 1
A getCoordinates() 8 8 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\Client\Purchase;
6
7
use LauLamanApps\IzettleApi\API\Purchase\Coordinates;
8
use LauLamanApps\IzettleApi\Client\Purchase\CoordinatesBuilder;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @small
13
 */
14
final class CoordinatesBuilderTest extends TestCase
15
{
16
    /**
17
     * @test
18
     * @dataProvider getCoordinates
19
     */
20
    public function parse(float $latitude, float $longitude, float $accuracyMeters): void
21
    {
22
        $data = [
23
            'latitude' => $latitude,
24
            'longitude' => $longitude,
25
            'accuracyMeters' => $accuracyMeters,
26
        ];
27
28
        $builder = new CoordinatesBuilder();
29
        $coordinate = $builder->buildFromArray($data);
30
31
        self::assertInstanceOf(Coordinates::class, $coordinate);
32
        self::assertSame($latitude, $coordinate->getLatitude());
33
        self::assertSame($longitude, $coordinate->getLongitude());
34
        self::assertSame($accuracyMeters, $coordinate->getAccuracyMeters());
35
    }
36
37 View Code Duplication
    public function getCoordinates(): array
38
    {
39
        return [
40
            'Almere Poort, The Netherlands' => [52.3504547, 5.1511458, 10],
41
            'Amsterdam, The Netherlands' => [52.3702157, 4.8951679, 0],
42
            'Den Haag, The Netherlands' => [52.0704978, 4.3006999, -10.1],
43
        ];
44
    }
45
}
46