KeyTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 83.82 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 57
loc 68
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testOutput() 12 12 1
A testFactory() 11 11 1
A testFromText() 13 13 1
A testWire() 21 21 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\Algorithms;
17
use Badcow\DNS\Rdata\Factory;
18
use Badcow\DNS\Rdata\KEY;
19
use PHPUnit\Framework\TestCase;
20
21
class KeyTest extends TestCase
22
{
23
    /**
24
     * @var string
25
     */
26
    private static $publicKey = 'AQPSKmynfzW4kyBv015MUG2DeIQ3Cbl+BBZH4b/0PY1kxkmvHjcZc8nokfzj31GajIQKY+5CptLr3buXA10hWqTkF7H6RfoRqXQeogmMHfpftf6zMv1LyBUgia7za6ZEzOJBOztyvhjL742iU/TpPSEDhm2SNKLijfUppn1UaNvv4w==';
27
28 View Code Duplication
    public function testOutput(): 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...
29
    {
30
        $expectation = '256 3 5 '.self::$publicKey;
31
32
        $key = new KEY();
33
        $key->setFlags(256);
34
        $key->setProtocol(3);
35
        $key->setAlgorithm(Algorithms::RSASHA1);
36
        $key->setPublicKey(base64_decode(self::$publicKey));
37
38
        $this->assertEquals($expectation, $key->toText());
39
    }
40
41 View Code Duplication
    public function testFactory(): 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...
42
    {
43
        $key = Factory::KEY(256, 3, Algorithms::RSASHA1, base64_decode(self::$publicKey));
44
        $output = '256 3 5 '.self::$publicKey;
45
46
        $this->assertEquals(256, $key->getFlags());
47
        $this->assertEquals(5, $key->getAlgorithm());
48
        $this->assertEquals(base64_decode(self::$publicKey), $key->getPublicKey());
49
        $this->assertEquals(3, $key->getProtocol());
50
        $this->assertEquals($output, $key->toText());
51
    }
52
53 View Code Duplication
    public function testFromText(): 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...
54
    {
55
        $rdata = '256 3 5 AQPSKmynfzW4kyBv015MUG2DeIQ3 Cbl+BBZH4b/0PY1kxkmvHjcZc8no kfzj31GajIQKY+5CptLr3buXA10h WqTkF7H6RfoRqXQeogmMHfpftf6z Mv1LyBUgia7za6ZEzOJBOztyvhjL 742iU/TpPSEDhm2SNKLijfUppn1U aNvv4w==';
56
        $key = new KEY();
57
        $key->setFlags(256);
58
        $key->setProtocol(3);
59
        $key->setAlgorithm(Algorithms::RSASHA1);
60
        $key->setPublicKey(base64_decode(self::$publicKey));
61
62
        $fromText = new KEY();
63
        $fromText->fromText($rdata);
64
        $this->assertEquals($key, $fromText);
65
    }
66
67 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...
68
    {
69
        $wireFormat = pack('nCC', 256, 3, 5).base64_decode(self::$publicKey);
70
71
        $key = new KEY();
72
        $key->setFlags(256);
73
        $key->setProtocol(3);
74
        $key->setAlgorithm(Algorithms::RSASHA1);
75
        $key->setPublicKey(base64_decode("AQPSKmynfzW4kyBv015MUG2DeIQ3Cbl+BBZH4b/\r\n0PY1kxkmvHjcZc8nokfzj31GajIQKY+5CptLr3buXA10hWqTkF7H6RfoRqXQe   ogmMHfpftf6zMv1LyBUgia7za6ZEzOJBOztyvhjL742iU\n/TpPSEDhm2SNKLijfUppn1UaNvv4w=="));
76
77
        $this->assertEquals($wireFormat, $key->toWire());
78
79
        $rdLength = strlen($wireFormat);
80
        $wireFormat = 'abcde'.$wireFormat.'fghijk';
81
        $offset = 5;
82
83
        $fromWire = new KEY();
84
        $fromWire->fromWire($wireFormat, $offset, $rdLength);
85
        $this->assertEquals($key, $fromWire);
86
        $this->assertEquals(5 + $rdLength, $offset);
87
    }
88
}
89