Completed
Push — master ( 3d39f9...d9b5c0 )
by Anthony
07:02 queued 04:32
created

HashTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 45
loc 45
rs 10

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
namespace RandomLib\Mixer;
4
5
use SecurityLib\Strength;
6
7
class HashTest extends \PHPUnit_Framework_TestCase {
8
9
    public static function provideMix() {
10
        $data = array(
11
            array(array(), ''),
12
            array(array('1', '1'), '0d'),
13
            array(array('a'), '61'),
14
            // This expects 'b' because of how the mock hmac function works
15
            array(array('a', 'b'), '9a'),
16
            array(array('aa', 'ba'), '6e84'),
17
            array(array('ab', 'bb'), 'b0cb'),
18
            array(array('aa', 'bb'), 'ae8d'),
19
            array(array('aa', 'bb', 'cc'), 'a14c'),
20
            array(array('aabbcc', 'bbccdd', 'ccddee'), 'a8aff3939934'),
21
        );
22
        return $data;
23
    }
24
25
    public function testConstructWithoutArgument() {
26
        $hash = new Hash;
27
        $this->assertTrue($hash instanceof \RandomLib\Mixer);
28
    }
29
30
    public function testGetStrength() {
31
        $strength = new Strength(Strength::MEDIUM);
32
        $actual = Hash::getStrength();
33
        $this->assertEquals($actual, $strength);
34
    }
35
36
    public function testTest() {
37
        $actual = Hash::test();
38
        $this->assertTrue($actual);
39
    }
40
41
    /**
42
     * @dataProvider provideMix
43
     */
44
    public function testMix($parts, $result) {
45
        $mixer = new Hash('md5');
46
        $actual = $mixer->mix($parts);
47
        $this->assertEquals($result, bin2hex($actual));
48
    }
49
50
51
}
52