LocTest   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 189
Duplicated Lines 29.63 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 2
dl 56
loc 189
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testOutput() 0 13 1
A testSetLatitude() 12 12 1
A testSetLongitude() 12 12 1
A testSetAltitude1() 8 8 1
A testSetAltitude2() 0 8 1
A testGetAltitude() 0 7 1
A testSetSize1() 8 8 1
A testSetSize2() 0 8 1
A testGetSize() 0 7 1
A testSetVerticalPrecision1() 8 8 1
A testSetVerticalPrecision2() 0 8 1
A testSetHorizontalPrecision1() 8 8 1
A testSetHorizontalPrecision2() 0 8 1
A testGetHorizontalPrecision() 0 7 1
A testGetVerticalPrecision() 0 7 1
A testWire() 0 18 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
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Tests\Rdata;
15
16
use Badcow\DNS\Rdata\LOC;
17
use PHPUnit\Framework\TestCase;
18
19
class LocTest extends TestCase
20
{
21
    public function testOutput(): void
22
    {
23
        $rdata = new LOC();
24
        $rdata->setLatitude(-35.3075);
25
        $rdata->setLongitude(149.1244);
26
        $rdata->setAltitude(500);
27
        $rdata->setSize(20.12);
28
        $rdata->setHorizontalPrecision(200.3);
29
        $rdata->setVerticalPrecision(300.1);
30
31
        $expected = '35 18 27.000 S 149 7 27.840 E 500.00m 20.12m 200.30m 300.10m';
32
        $this->assertEquals($expected, $rdata->toText());
33
    }
34
35 View Code Duplication
    public function testSetLatitude(): void
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...
36
    {
37
        $latitude = -35.3075;
38
        $lat_dms = '35 18 27.000 S';
39
40
        $rdata = new LOC();
41
        $rdata->setLatitude($latitude);
42
43
        $this->assertEquals($latitude, $rdata->getLatitude());
44
        $this->assertEquals($latitude, $rdata->getLatitude(LOC::FORMAT_DECIMAL));
45
        $this->assertEquals($lat_dms, $rdata->getLatitude(LOC::FORMAT_DMS));
46
    }
47
48 View Code Duplication
    public function testSetLongitude(): void
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...
49
    {
50
        $longitude = 149.1244;
51
        $lon_dms = '149 7 27.840 E';
52
53
        $rdata = new LOC();
54
        $rdata->setLongitude($longitude);
55
56
        $this->assertEquals($longitude, $rdata->getLongitude());
57
        $this->assertEquals($longitude, $rdata->getLongitude(LOC::FORMAT_DECIMAL));
58
        $this->assertEquals($lon_dms, $rdata->getLongitude(LOC::FORMAT_DMS));
59
    }
60
61
    /**
62
     * @throws \OutOfRangeException
63
     */
64 View Code Duplication
    public function testSetAltitude1(): void
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...
65
    {
66
        $this->expectException(\OutOfRangeException::class);
67
        $this->expectExceptionMessage('The altitude must be on [-100000.00, 42849672.95].');
68
69
        $rdata = new LOC();
70
        $rdata->setAltitude(-100001);
71
    }
72
73
    /**
74
     * @throws \OutOfRangeException
75
     */
76
    public function testSetAltitude2(): void
77
    {
78
        $this->expectException(\OutOfRangeException::class);
79
        $this->expectExceptionMessage('The altitude must be on [-100000.00, 42849672.95].');
80
81
        $rdata = new LOC();
82
        $rdata->setAltitude(42849673);
83
    }
84
85
    public function testGetAltitude(): void
86
    {
87
        $rdata = new LOC();
88
        $altitude = 12345;
89
        $rdata->setAltitude($altitude);
90
        $this->assertEquals($altitude, $rdata->getAltitude());
91
    }
92
93
    /**
94
     * @thows \OutOfRangeException
95
     */
96 View Code Duplication
    public function testSetSize1(): void
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...
97
    {
98
        $this->expectException(\OutOfRangeException::class);
99
        $this->expectExceptionMessage('The size must be on [0, 9e9].');
100
101
        $rdata = new LOC();
102
        $rdata->setSize(-1);
103
    }
104
105
    /**
106
     * @throws \OutOfRangeException
107
     */
108
    public function testSetSize2(): void
109
    {
110
        $this->expectException(\OutOfRangeException::class);
111
        $this->expectExceptionMessage('The size must be on [0, 9e9].');
112
113
        $rdata = new LOC();
114
        $rdata->setSize(9000000002);
115
    }
116
117
    public function testGetSize(): void
118
    {
119
        $size = 1231;
120
        $rdata = new LOC();
121
        $rdata->setSize($size);
122
        $this->assertEquals($size, $rdata->getSize());
123
    }
124
125
    /**
126
     * @throws \OutOfRangeException
127
     */
128 View Code Duplication
    public function testSetVerticalPrecision1(): void
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...
129
    {
130
        $this->expectException(\OutOfRangeException::class);
131
        $this->expectExceptionMessage('The vertical precision must be on [0, 9e9].');
132
133
        $rdata = new LOC();
134
        $rdata->setVerticalPrecision(-1);
135
    }
136
137
    /**
138
     * @throws \OutOfRangeException
139
     */
140
    public function testSetVerticalPrecision2(): void
141
    {
142
        $this->expectException(\OutOfRangeException::class);
143
        $this->expectExceptionMessage('The vertical precision must be on [0, 9e9].');
144
145
        $rdata = new LOC();
146
        $rdata->setVerticalPrecision(9000000002);
147
    }
148
149
    /**
150
     * @throws \OutOfRangeException
151
     */
152 View Code Duplication
    public function testSetHorizontalPrecision1(): void
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...
153
    {
154
        $this->expectException(\OutOfRangeException::class);
155
        $this->expectExceptionMessage('The horizontal precision must be on [0, 9e9].');
156
157
        $rdata = new LOC();
158
        $rdata->setHorizontalPrecision(-1);
159
    }
160
161
    /**
162
     * @throws \OutOfRangeException
163
     */
164
    public function testSetHorizontalPrecision2(): void
165
    {
166
        $this->expectException(\OutOfRangeException::class);
167
        $this->expectExceptionMessage('The horizontal precision must be on [0, 9e9].');
168
169
        $rdata = new LOC();
170
        $rdata->setHorizontalPrecision(9000000002);
171
    }
172
173
    public function testGetHorizontalPrecision(): void
174
    {
175
        $hp = 127835;
176
        $rdata = new LOC();
177
        $rdata->setHorizontalPrecision($hp);
178
        $this->assertEquals($hp, $rdata->getHorizontalPrecision());
179
    }
180
181
    public function testGetVerticalPrecision(): void
182
    {
183
        $vp = 127835;
184
        $rdata = new LOC();
185
        $rdata->setVerticalPrecision($vp);
186
        $this->assertEquals($vp, $rdata->getVerticalPrecision());
187
    }
188
189
    public function testWire(): void
190
    {
191
        $loc = new LOC();
192
        $loc->setLatitude(-35.3075);
193
        $loc->setLongitude(149.1244);
194
        $loc->setAltitude(500);
195
        $loc->setSize(200);
196
        $loc->setHorizontalPrecision(200);
197
        $loc->setVerticalPrecision(300);
198
199
        $wireFormat = 'abc'.$loc->toWire();
200
        $offset = 3;
201
202
        $fromWire = new LOC();
203
        $fromWire->fromWire($wireFormat, $offset);
204
        $this->assertEquals($loc, $fromWire);
205
        $this->assertEquals(19, $offset);
206
    }
207
}
208