LocationTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 57.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 3
dl 58
loc 101
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuccessfulCreation() 0 16 1
A testMissingNameFields() 11 11 1
A testMissingCoordinatesField() 0 8 1
A testMissingLatField() 11 11 1
A testNameWrongType() 12 12 1
A testCoordinatesWrongType() 0 9 1
A testLatWrongType() 12 12 1
A testLongWrongType() 12 12 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 AlexeyKuperhstokh\LocationBundle\Tests\Location;
4
5
use AlexeyKuperhstokh\LocationBundle\Location\Location;
6
7
class LocationTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testSuccessfulCreation()
10
    {
11
        $options = [
12
            "name" => "Eiffel Tower",
13
            "coordinates" => [
14
                "lat" => 21.12,
15
                "long" => 19.56
16
            ]
17
        ];
18
19
        $loc = new Location($options);
20
        $this->assertEquals('Eiffel Tower', $loc->getName());
21
        $this->assertInstanceOf('\AlexeyKuperhstokh\LocationBundle\Location\Coordinates', $loc->getCoordinates());
22
        $this->assertEquals(21.12, $loc->getCoordinates()->getLat());
23
        $this->assertEquals(19.56, $loc->getCoordinates()->getLong());
24
    }
25
26 View Code Duplication
    public function testMissingNameFields()
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...
27
    {
28
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException');
29
        $options = [
30
            "coordinates" => [
31
                "lat" => 21.12,
32
                "long" => 19.56
33
            ]
34
        ];
35
        new Location($options);
36
    }
37
38
    public function testMissingCoordinatesField()
39
    {
40
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException');
41
        $options = [
42
            "name" => "Eiffel Tower",
43
        ];
44
        new Location($options);
45
    }
46
47 View Code Duplication
    public function testMissingLatField()
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...
48
    {
49
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException');
50
        $options = [
51
            "name" => "Eiffel Tower",
52
            "coordinates" => [
53
                "lat" => 21.12,
54
            ]
55
        ];
56
        new Location($options);
57
    }
58
59 View Code Duplication
    public function testNameWrongType()
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...
60
    {
61
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
62
        $options = [
63
            "name" => [],
64
            "coordinates" => [
65
                "lat" => 21.12,
66
                "long" => 19.56
67
            ]
68
        ];
69
        new Location($options);
70
    }
71
72
    public function testCoordinatesWrongType()
73
    {
74
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
75
        $options = [
76
            "name" => [],
77
            "coordinates" => true
78
        ];
79
        new Location($options);
80
    }
81
82 View Code Duplication
    public function testLatWrongType()
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...
83
    {
84
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
85
        $options = [
86
            "name" => 'Eiffel Tower',
87
            "coordinates" => [
88
                'lat' => [],
89
                'long' => 19.56,
90
            ]
91
        ];
92
        new Location($options);
93
    }
94
95 View Code Duplication
    public function testLongWrongType()
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...
96
    {
97
        $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
98
        $options = [
99
            "name" => 'Eiffel Tower',
100
            "coordinates" => [
101
                'lat' => 19.56,
102
                'long' => "",
103
            ]
104
        ];
105
        new Location($options);
106
    }
107
}
108