AfsdbTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 48.48 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testOutput() 0 9 1
A testOutputThrowsExceptionWhenMissingSubType() 9 9 1
A testOutputThrowsExceptionWhenMissingHostname() 9 9 1
A testFromText() 0 10 1
A testWire() 14 14 1
A testFactory() 0 7 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\AFSDB;
17
use Badcow\DNS\Rdata\Factory;
18
use PHPUnit\Framework\TestCase;
19
20
/**
21
 * {@link https://tools.ietf.org/html/rfc1183}.
22
 */
23
class AfsdbTest extends TestCase
24
{
25
    public function testOutput(): void
26
    {
27
        $hostname = 'foo.example.com.';
28
        $afsdb = new AFSDB();
29
        $afsdb->setHostname($hostname);
30
        $afsdb->setSubType(2);
31
32
        $this->assertEquals('2 foo.example.com.', $afsdb->toText());
33
    }
34
35 View Code Duplication
    public function testOutputThrowsExceptionWhenMissingSubType(): 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
        $afsdb = new AFSDB();
38
        $afsdb->setHostname('foo.example.com.');
39
40
        $this->expectException(\InvalidArgumentException::class);
41
        $this->expectExceptionMessage('No sub-type has been set on AFSDB object.');
42
        $afsdb->toText();
43
    }
44
45 View Code Duplication
    public function testOutputThrowsExceptionWhenMissingHostname(): 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...
46
    {
47
        $afsdb = new AFSDB();
48
        $afsdb->setSubType(15);
49
50
        $this->expectException(\InvalidArgumentException::class);
51
        $this->expectExceptionMessage('No hostname has been set on AFSDB object.');
52
        $afsdb->toText();
53
    }
54
55
    public function testFromText(): void
56
    {
57
        $text = '2 foo.example.com.';
58
        /** @var AFSDB $afsdb */
59
        $afsdb = new AFSDB();
60
        $afsdb->fromText($text);
61
62
        $this->assertEquals(2, $afsdb->getSubType());
63
        $this->assertEquals('foo.example.com.', $afsdb->getHostname());
64
    }
65
66 View Code Duplication
    public function testWire(): 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...
67
    {
68
        $afsdb = new AFSDB();
69
        $afsdb->setHostname('foo.example.com.');
70
        $afsdb->setSubType(2);
71
72
        $expectation = pack('n', 2).chr(3).'foo'.chr(7).'example'.chr(3).'com'.chr(0);
73
74
        $fromWire = new AFSDB();
75
        $fromWire->fromWire($expectation);
76
77
        $this->assertEquals($expectation, $afsdb->toWire());
78
        $this->assertEquals($afsdb, $fromWire);
79
    }
80
81
    public function testFactory(): void
82
    {
83
        $afsdb = Factory::AFSDB(2, 'foo.example.com.');
84
85
        $this->assertInstanceOf(AFSDB::class, $afsdb);
86
        $this->assertEquals('2 foo.example.com.', $afsdb->toText());
87
    }
88
}
89