Completed
Push — master ( 61c19f...f7d981 )
by Peter
03:44
created

ReflectionEnumNoMagicBench   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 45
loc 45
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A benchInit() 4 4 1
A benchCompareSelf() 5 5 1
A benchInitTwice() 5 5 1
A benchInitTwiceDifferentValue() 5 5 1
A benchCompareDifferent() 4 4 1
A benchToString() 4 4 1
A benchBuildChoices() 4 4 1
A benchBuildValues() 4 4 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
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2017, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Enum\Bench\Segregate;
12
13
use GpsLab\Component\Enum\Tests\Fixture\Enum\DefRef;
14
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
15
use PhpBench\Benchmark\Metadata\Annotations\Revs;
16
17
/**
18
 * @Revs(2500)
19
 * @Iterations(25)
20
 */
21 View Code Duplication
class ReflectionEnumNoMagicBench implements SegregateEnumBench
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    public function benchInit()
24
    {
25
        $d = DefRef::byValue(DefRef::D);
0 ignored issues
show
Unused Code introduced by
$d is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
    }
27
28
    public function benchCompareSelf()
29
    {
30
        $d = DefRef::byValue(DefRef::D);
31
        $d->equals(DefRef::byValue(DefRef::D));
32
    }
33
34
    public function benchInitTwice()
35
    {
36
        $d = DefRef::byValue(DefRef::D);
0 ignored issues
show
Unused Code introduced by
$d is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
37
        $z = DefRef::byValue(DefRef::D);
0 ignored issues
show
Unused Code introduced by
$z is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
    }
39
40
    public function benchInitTwiceDifferentValue()
41
    {
42
        $d = DefRef::byValue(DefRef::D);
0 ignored issues
show
Unused Code introduced by
$d is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
        $e = DefRef::byValue(DefRef::E);
0 ignored issues
show
Unused Code introduced by
$e is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
    }
45
46
    public function benchCompareDifferent()
47
    {
48
        DefRef::byValue(DefRef::D)->equals(DefRef::byValue(DefRef::E));
49
    }
50
51
    public function benchToString()
52
    {
53
        $f = (string) DefRef::byValue(DefRef::F);
0 ignored issues
show
Unused Code introduced by
$f is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
    }
55
56
    public function benchBuildChoices()
57
    {
58
        DefRef::choices();
59
    }
60
61
    public function benchBuildValues()
62
    {
63
        DefRef::values();
64
    }
65
}
66