Completed
Push — feature/bench ( ba5640...eaf7cd )
by Marc
01:19
created

EnumBench::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace MabeEnumBench;
4
5
use MabeEnumTest\TestAsset\Enum66;
6
7
/**
8
 * Benchmark of abstract class Enum tested with enumeration of 66 enumerators.
9
 *
10
 * @BeforeMethods({"init"})
11
 * @Revs(2500)
12
 * @Iterations(25)
13
 */
14
class EnumBench
15
{
16
    /**
17
     * @var array
18
     */
19
    private $constants;
20
21
    /**
22
     * @var string[]
23
     */
24
    private $names;
25
26
    /**
27
     * @var mixed[]
28
     */
29
    private $values;
30
31
    /**
32
     * @var int[]
33
     */
34
    private $ordinals;
35
36
    /**
37
     * @var Enum66[]
38
     */
39
    private $enumerators;
40
41
    /**
42
     * Will be called before every subject
43
     */
44
    public function init()
45
    {
46
        $this->constants   = Enum66::getConstants();
47
        $this->names       = Enum66::getNames();
0 ignored issues
show
Documentation Bug introduced by
It seems like \MabeEnumTest\TestAsset\Enum66::getNames() of type array<integer,integer|string> is incompatible with the declared type array<integer,string> of property $names.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
        $this->values      = Enum66::getValues();
49
        $this->ordinals    = Enum66::getOrdinals();
50
        $this->enumerators = Enum66::getEnumerators();
0 ignored issues
show
Documentation Bug introduced by
It seems like \MabeEnumTest\TestAsset\Enum66::getEnumerators() of type array<integer,object<MabeEnum\Enum>> is incompatible with the declared type array<integer,object<Mab...Test\TestAsset\Enum66>> of property $enumerators.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
    }
52
53
    public function benchGetName()
54
    {
55
        foreach ($this->enumerators as $enumerator) {
56
            $enumerator->getName();
57
        }
58
    }
59
60
    public function benchGetValue()
61
    {
62
        foreach ($this->enumerators as $enumerator) {
63
            $enumerator->getValue();
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnumTest\TestAsset\Enum66::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...
64
        }
65
    }
66
67
    public function benchGetOrdinal()
68
    {
69
        foreach ($this->enumerators as $enumerator) {
70
            $enumerator->getOrdinal();
71
        }
72
    }
73
74
    public function benchIsByEnumerator()
75
    {
76
        foreach ($this->enumerators as $enumerator) {
77
            $enumerator->is($enumerator);
78
        }
79
    }
80
81
    public function benchIsByValue()
82
    {
83
        foreach ($this->enumerators as $enumerator) {
84
            $enumerator->is($enumerator->getValue());
85
        }
86
    }
87
88
    public function benchGetConstants()
89
    {
90
        Enum66::getConstants();
91
    }
92
93
    public function benchGetValues()
94
    {
95
        Enum66::getValues();
96
    }
97
98
    public function benchGetNames()
99
    {
100
        Enum66::getNames();
101
    }
102
103
    public function benchGetOrdinals()
104
    {
105
        Enum66::getOrdinals();
106
    }
107
108
    public function benchGetEnumerators()
109
    {
110
        Enum66::getEnumerators();
111
    }
112
113
    public function benchByValue()
114
    {
115
        foreach ($this->values as $value) {
116
            Enum66::byValue($value);
117
        }
118
    }
119
120
    public function benchByName()
121
    {
122
        foreach ($this->names as $name) {
123
            Enum66::byName($name);
124
        }
125
    }
126
127
    public function benchByOrdinal()
128
    {
129
        foreach ($this->ordinals as $ord) {
130
            Enum66::byOrdinal($ord);
131
        }
132
    }
133
134
    public function benchGetByValues()
135
    {
136
        foreach ($this->values as $value) {
137
            Enum66::get($value);
138
        }
139
    }
140
141
    public function benchGetByEnumerator()
142
    {
143
        foreach ($this->enumerators as $enumerator) {
144
            Enum66::get($enumerator);
145
        }
146
    }
147
148
    public function benchGetByCallStatic()
149
    {
150
        foreach ($this->names as $name) {
151
            Enum66::$name();
152
        }
153
    }
154
155
    public function benchHasByEnumerator()
156
    {
157
        foreach ($this->enumerators as $enumerator) {
158
            Enum66::has($enumerator);
159
        }
160
    }
161
162
    public function benchHasByValue()
163
    {
164
        foreach ($this->values as $value) {
165
            Enum66::has($value);
166
        }
167
    }
168
}
169