NsTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 44
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetNsdname() 8 8 1
A testOutput() 9 9 1
A testFromText() 9 9 1
A testWire() 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
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\NS;
17
use PHPUnit\Framework\TestCase;
18
19 View Code Duplication
class NsTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
20
{
21
    public function testSetNsdname(): void
22
    {
23
        $target = 'foo.example.com.';
24
        $ns = new NS();
25
        $ns->setTarget($target);
26
27
        $this->assertEquals($target, $ns->getTarget());
28
    }
29
30
    public function testOutput(): void
31
    {
32
        $target = 'foo.example.com.';
33
        $ns = new NS();
34
        $ns->setTarget($target);
35
36
        $this->assertEquals($target, $ns->toText());
37
        $this->assertEquals($target, $ns->toText());
38
    }
39
40
    public function testFromText(): void
41
    {
42
        $text = 'host.example.com.';
43
        /** @var NS $cname */
44
        $cname = new NS();
45
        $cname->fromText($text);
46
47
        $this->assertEquals($text, $cname->getTarget());
48
    }
49
50
    public function testWire(): void
51
    {
52
        $host = 'host.example.com.';
53
        $expectation = chr(4).'host'.chr(7).'example'.chr(3).'com'.chr(0);
54
55
        /** @var NS $ns */
56
        $ns = new NS();
57
        $ns->fromWire($expectation);
58
59
        $this->assertEquals($expectation, $ns->toWire());
60
        $this->assertEquals($host, $ns->getTarget());
61
    }
62
}
63