Completed
Push — feature/bench ( a60088 )
by Marc
05:26 queued 01:24
created

EnumBench   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 2
dl 0
loc 135
rs 9.6
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A initClass() 0 10 1
A benchGetName() 0 6 2
A benchGetValue() 0 6 2
A benchGetOrdinal() 0 6 2
A benchIsByEnumerator() 0 6 2
A benchIsByValue() 0 6 2
A benchGetConstants() 0 4 1
A benchGetValues() 0 4 1
A benchGetNames() 0 4 1
A benchGetOrdinals() 0 4 1
A benchGetEnumerators() 0 4 1
A benchByValue() 0 6 2
A benchByName() 0 6 2
A benchByOrdinal() 0 6 2
A benchGetByValues() 0 6 2
A benchGetByEnumerator() 0 6 2
A benchGetByCallStatic() 0 6 2
A benchHasByEnumerator() 0 6 2
A benchHasByValue() 0 6 2
1
<?php
2
3
namespace MabeEnumBench;
4
5
use MabeEnumTest\TestAsset\Enum66;
6
7
/**
8
 * @BeforeClassMethods({"initClass"})
9
 * @Revs(1000)
10
 * @Iterations(20)
11
 */
12
class EnumBench
13
{
14
    private static $constants;
15
    private static $names;
16
    private static $values;
17
    private static $ordinals;
18
    private static $enumerators;
19
20
    public static function initClass()
21
    {
22
        // initialize the enum to make sure the initialization process
23
        // will not effect the benchmark
24
        self::$constants   = Enum66::getConstants();
25
        self::$names       = Enum66::getNames();
26
        self::$values      = Enum66::getValues();
27
        self::$ordinals    = Enum66::getOrdinals();
28
        self::$enumerators = Enum66::getEnumerators();
29
    }
30
31
    public function benchGetName()
32
    {
33
        foreach (self::$enumerators as $enumerator) {
34
            $enumerator->getName();
35
        }
36
    }
37
38
    public function benchGetValue()
39
    {
40
        foreach (self::$enumerators as $enumerator) {
41
            $enumerator->getValue();
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\Enum::getValue() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
42
        }
43
    }
44
45
    public function benchGetOrdinal()
46
    {
47
        foreach (self::$enumerators as $enumerator) {
48
            $enumerator->getOrdinal();
49
        }
50
    }
51
52
    public function benchIsByEnumerator()
53
    {
54
        foreach (self::$enumerators as $enumerator) {
55
            $enumerator->is($enumerator);
56
        }
57
    }
58
59
    public function benchIsByValue()
60
    {
61
        foreach (self::$enumerators as $enumerator) {
62
            $enumerator->is($enumerator->getValue());
63
        }
64
    }
65
66
    public function benchGetConstants()
67
    {
68
        Enum66::getConstants();
69
    }
70
71
    public function benchGetValues()
72
    {
73
        Enum66::getValues();
74
    }
75
76
    public function benchGetNames()
77
    {
78
        Enum66::getNames();
79
    }
80
81
    public function benchGetOrdinals()
82
    {
83
        Enum66::getOrdinals();
84
    }
85
86
    public function benchGetEnumerators()
87
    {
88
        Enum66::getEnumerators();
89
    }
90
91
    public function benchByValue()
92
    {
93
        foreach (self::$values as $value) {
94
            Enum66::byValue($value);
95
        }
96
    }
97
98
    public function benchByName()
99
    {
100
        foreach (self::$names as $name) {
101
            Enum66::byName($name);
102
        }
103
    }
104
105
    public function benchByOrdinal()
106
    {
107
        foreach (self::$ordinals as $ord) {
108
            Enum66::byOrdinal($ord);
109
        }
110
    }
111
112
    public function benchGetByValues()
113
    {
114
        foreach (self::$values as $value) {
115
            Enum66::get($value);
116
        }
117
    }
118
119
    public function benchGetByEnumerator()
120
    {
121
        foreach (self::$enumerators as $enumerator) {
122
            Enum66::get($enumerator);
123
        }
124
    }
125
126
    public function benchGetByCallStatic()
127
    {
128
        foreach (self::$names as $name) {
129
            Enum66::$name();
130
        }
131
    }
132
133
    public function benchHasByEnumerator()
134
    {
135
        foreach (self::$enumerators as $enumerator) {
136
            Enum66::has($enumerator);
137
        }
138
    }
139
140
    public function benchHasByValue()
141
    {
142
        foreach (self::$values as $value) {
143
            Enum66::has($value);
144
        }
145
    }
146
}
147