Completed
Push — master ( a19d10...c6e8cc )
by Jacob
02:16
created

DisplayTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 69.77 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 30
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetReadableTime() 15 15 2
A testGetReadableMemory() 15 15 2
A getAccessibleMethod() 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
namespace Particletree\Pqp;
4
5
use PHPUnit_Framework_TestCase;
6
use ReflectionClass;
7
8
class DisplayTest extends PHPUnit_Framework_TestCase
9
{
10
11 View Code Duplication
    public function testGetReadableTime()
1 ignored issue
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...
12
    {
13
        $timeTest = array(
14
            '.032432' => '32.432 ms',
15
            '24.3781' => '24.378 s',
16
            '145.123' => '2.419 m'
17
        );
18
        $display = new Display();
19
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableTime');
20
21
        foreach ($timeTest as $rawTime => $expectedReadableTime) {
22
            $readableTime = $reflectedMethod->invokeArgs($display, array($rawTime));
23
            $this->assertEquals($expectedReadableTime, $readableTime);
24
        }
25
    }
26
27 View Code Duplication
    public function testGetReadableMemory()
1 ignored issue
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...
28
    {
29
        $memoryTest = array(
30
            '314'     => '314 b',
31
            '7403'    => '7.23 k',
32
            '2589983' => '2.47 M'
33
        );
34
        $display = new Display();
35
        $reflectedMethod = $this->getAccessibleMethod($display, 'getReadableMemory');
36
37
        foreach ($memoryTest as $rawMemory => $expectedReadableMemory) {
38
            $readableMemory = $reflectedMethod->invokeArgs($display, array($rawMemory));
39
            $this->assertEquals($expectedReadableMemory, $readableMemory);
40
        }
41
    }
42
43
    protected function getAccessibleMethod(Display $display, $methodName)
44
    {
45
        $reflectedConsole = new ReflectionClass(get_class($display));
46
        $reflectedMethod = $reflectedConsole->getMethod($methodName);
47
        $reflectedMethod->setAccessible(true);
48
        return $reflectedMethod;
49
    }
50
}
51