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

MTRandTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 34
loc 34
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\Source;
4
5
use SecurityLib\Strength;
6
7
8
9
class MTRandTest extends \PHPUnit_Framework_TestCase {
10
11
    public static function provideGenerate() {
12
        $data = array();
13
        for ($i = 0; $i < 100; $i += 5) {
14
            $not = $i > 0 ? str_repeat(chr(0), $i) : chr(0);
15
            $data[] = array($i, $not);
16
        }
17
        return $data;
18
    }
19
20
    /**
21
     */
22
    public function testGetStrength() {
23
        if (defined('S_ALL')) {
24
            $strength = new Strength(Strength::MEDIUM);
25
        } else {
26
            $strength = new Strength(Strength::LOW);
27
        }
28
        $actual = MTRand::getStrength();
29
        $this->assertEquals($actual, $strength);
30
    }
31
32
    /**
33
     * @dataProvider provideGenerate
34
     */
35
    public function testGenerate($length, $not) {
36
        $rand = new MTRand;
37
        $stub = $rand->generate($length);
38
        $this->assertEquals($length, strlen($stub));
39
        $this->assertNotEquals($not, $stub);
40
    }
41
42
}
43