Completed
Push — master ( b814cf...f1473b )
by Kamran
13:45 queued 06:55
created

GeocodeTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 28 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 7
lcom 1
cbo 3
dl 28
loc 100
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeocode() 0 10 2
A testInvalidLocation() 0 7 1
A testEmptyOrNullAdress() 0 5 1
A testGeocodeProtocol() 14 14 1
A testGeocodeKey() 14 14 1
B providerTestGeocodeProvider() 0 32 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
namespace KamranAhmed\Geocode;
4
5
class GeocodeTest extends \PHPUnit_Framework_TestCase
6
{
7
8
    /**
9
     * @dataProvider providerTestGeocodeProvider
10
     */
11
    public function testGeocode($address, $expected)
12
    {
13
        $actual = new Geocode();
14
        $location = $actual->get($address);
15
        $methods = array_keys($expected);
16
        $this->assertTrue($location->isValid());
17
        foreach ($methods as $method) {
18
            $this->assertEquals($expected[$method], $location->$method());
19
        }
20
    }
21
22
23
    public function testInvalidLocation()
24
    {
25
        $geo= new Geocode();
26
        $location = $geo->get("House of the rights for the poor people");
27
        $this->assertFalse($location->isValid());
28
 
29
    }
30
    /**
31
    *@test
32
    *@expectedException \Exception
33
    *@expectedExceptionMessage Address is required in order to process
34
    */
35
    public function testEmptyOrNullAdress()
36
    {
37
        $actual = new Geocode();
38
        $actual->get("");
39
    }
40
41 View Code Duplication
    public function testGeocodeProtocol()
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...
42
    {
43
        $actual = new Geocode();
44
        $this->assertEquals(
45
            'http://maps.googleapis.com/maps/api/geocode/json?',
46
            $actual->getServiceUrl()
47
        );
48
49
        $actual = new Geocode();
50
        $this->assertEquals(
51
            'http://maps.googleapis.com/maps/api/geocode/json?',
52
            $actual->getServiceUrl()
53
        );
54
    }
55
56 View Code Duplication
    public function testGeocodeKey()
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...
57
    {
58
        $actual = new Geocode('DUMMYKEY');
59
        $this->assertEquals(
60
            'https://maps.googleapis.com/maps/api/geocode/json?key=DUMMYKEY',
61
            $actual->getServiceUrl()
62
        );
63
64
        $actual = new Geocode('DUMMYKEY');
65
        $this->assertEquals(
66
            'https://maps.googleapis.com/maps/api/geocode/json?key=DUMMYKEY',
67
            $actual->getServiceUrl()
68
        );
69
    }
70
71
 
72
    public function providerTestGeocodeProvider()
73
    {
74
        $providers = array();
75
76
        $providers[] = array(
77
                "1600 Amphitheatre Parkway, Mountain View, CA",
78
                array(
79
                    'getAddress' => '1600 Amphitheatre Parkway, Mountain View, CA',
80
                    'getCountry' => 'United States',
81
                    'getLocality' => 'Mountain View',
82
                    'getDistrict' => 'California',
83
                    'getPostcode' => '94043',
84
                    'getStreetAddress' => 'Amphitheatre Parkway',
85
                    'getStreetNumber' => '1600'
86
                )
87
            );
88
89
        $providers[] = array(
90
                "9 Little St, Beachburg, Ontario, Canada",
91
                array(
92
                    'getAddress' => '9 Little St, Beachburg, Ontario, Canada',
93
                    'getCountry' => 'Canada',
94
                    'getLocality' => 'Beachburg',
95
                    'getDistrict' => 'Ontario',
96
                    'getPostcode' => 'K0J 1C0',
97
                    'getTown' => '',
98
                    'getStreetNumber' => '9'
99
                )
100
            );
101
102
        return $providers;
103
    }
104
}
105