DiffrentTextfileCSRTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 21.88 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 3
dl 14
loc 64
ccs 40
cts 40
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A checkresponse() 0 6 1
A testWithEmptyresponse() 0 6 1
A testWithTrailingReturn() 0 6 1
A testWithJustSH1() 0 6 1
A testWithSH1AndComdoText() 7 7 1
A testWithSH1AndComdoTextNoTrailingReturn() 7 7 1
A testWithSH1AndComdoTextAndNewLine() 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
 * @author     Chris Hilsdon <[email protected]>
4
 * @package    ComodoDecodeCSR
5
 * @copyright  2016 Xigen
6
 * @license    GNU General Public License v3
7
 * @link       https://github.com/XigenChris/ComodoDecodeCSR
8
 */
9
10
namespace Xigen\Tests;
11
12
use GuzzleHttp\Psr7;
13
use GuzzleHttp\Psr7\Response;
14
15
use Xigen\ComodoDecodeCSR;
16
17
class DiffrentTextfileCSRTest extends XigenUnit
18
{
19 6
    protected $ComodoDecodeCSR;
20
    protected $Hashes;
21 6
22 6
    public function setUp()
23 6
    {
24 6
        $this->ComodoDecodeCSR = new ComodoDecodeCSR();
25
        $this->ComodoDecodeCSR->setCSR($this->loadTestCSR());
26 6
        $this->Hashes = $this->ComodoDecodeCSR->fetchHashes();
27
    }
28 6
29
    private function checkresponse($response)
30
    {
31 1
        $stream = Psr7\stream_for($response);
32
        $response = new Response(200, [], $stream);
33 1
        return $this->ComodoDecodeCSR->checkDVC($response);
34 1
    }
35 1
36 1
    public function testWithEmptyresponse()
37
    {
38 1
        $response = "";
39
        $test = $this->checkresponse($response);
40 1
        $this->assertFalse($test);
41 1
    }
42 1
43 1
    public function testWithTrailingReturn()
44
    {
45 1
        $response = "\n";
46
        $test = $this->checkresponse($response);
47 1
        $this->assertFalse($test);
48 1
    }
49 1
50 1
    public function testWithJustSH1()
51
    {
52 1
        $response = $this->validSHA1 . "\n";
53
        $test = $this->checkresponse($response);
54 1
        $this->assertFalse($test);
55 1
    }
56 1
57 1 View Code Duplication
    public function testWithSH1AndComdoText()
58 1
    {
59
        $response = $this->validSHA1 . "\n";
60 1
        $response .= "comodoca.com\n";
61
        $test = $this->checkresponse($response);
62 1
        $this->assertTrue($test);
63 1
    }
64 1
65 1 View Code Duplication
    public function testWithSH1AndComdoTextNoTrailingReturn()
66 1
    {
67
        $response = $this->validSHA1 . "\n";
68 1
        $response .= "comodoca.com";
69
        $test = $this->checkresponse($response);
70 1
        $this->assertTrue($test);
71 1
    }
72 1
73 1
    public function testWithSH1AndComdoTextAndNewLine()
74 1
    {
75
        $response = $this->validSHA1 . "\n";
76
        $response .= "comodoca.com\n\n";
77
        $test = $this->checkresponse($response);
78
        $this->assertTrue($test);
79
    }
80
}
81