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

EnumSet66Bench::initClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
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 MabeEnum\EnumSet;
6
use MabeEnumTest\TestAsset\Enum66;
7
8
/**
9
 * Benchmark of EnumSet used with an enumeration of 66 enumerators.
10
 * (The internal bitset have to be a binary string)
11
 *
12
 * @BeforeMethods({"init"})
13
 * @Revs(2000)
14
 * @Iterations(25)
15
 */
16 View Code Duplication
class EnumSet66Bench
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...
17
{
18
    /**
19
     * @var array
20
     */
21
    private $constants;
22
23
    /**
24
     * @var string[]
25
     */
26
    private $names;
27
28
    /**
29
     * @var mixed[]
30
     */
31
    private $values;
32
33
    /**
34
     * @var int[]
35
     */
36
    private $ordinals;
37
38
    /**
39
     * @var Enum66[]
40
     */
41
    private $enumerators;
42
43
    /**
44
     * @var EnumSet
45
     */
46
    private $emptySet;
47
48
    /**
49
     * @var EnumSet
50
     */
51
    private $fullSet;
52
53
    /**
54
     * Will be called before every subject
55
     */
56
    public function init()
57
    {
58
        $this->constants   = Enum66::getConstants();
59
        $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...
60
        $this->values      = Enum66::getValues();
61
        $this->ordinals    = Enum66::getOrdinals();
62
        $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...
63
64
        $this->emptySet = new EnumSet(Enum66::class);
65
        $this->fullSet  = new EnumSet(Enum66::class);
66
        foreach ($this->enumerators as $enumerator) {
67
            $this->fullSet->attach($enumerator);
68
        }
69
    }
70
71
    public function benchAttachEnumeratorOnEmpty()
72
    {
73
        foreach ($this->enumerators as $enumerator) {
74
            $this->emptySet->attach($enumerator);
75
        }
76
    }
77
78
    public function benchAttachValueOnEmpty()
79
    {
80
        foreach ($this->values as $value) {
81
            $this->emptySet->attach($value);
82
        }
83
    }
84
85
    public function benchAttachEnumeratorOnFull()
86
    {
87
        foreach ($this->enumerators as $enumerator) {
88
            $this->fullSet->attach($enumerator);
89
        }
90
    }
91
92
    public function benchAttachValueOnFull()
93
    {
94
        foreach ($this->values as $value) {
95
            $this->fullSet->attach($value);
96
        }
97
    }
98
99
    public function benchDetachEnumeratorOnEmpty()
100
    {
101
        foreach ($this->enumerators as $enumerator) {
102
            $this->emptySet->detach($enumerator);
103
        }
104
    }
105
106
    public function benchDetachValueOnEmpty()
107
    {
108
        foreach ($this->values as $value) {
109
            $this->emptySet->detach($value);
110
        }
111
    }
112
113
    public function benchDetachEnumeratorOnFull()
114
    {
115
        foreach ($this->enumerators as $enumerator) {
116
            $this->fullSet->detach($enumerator);
117
        }
118
    }
119
120
    public function benchDetachValueOnFull()
121
    {
122
        foreach ($this->values as $value) {
123
            $this->fullSet->detach($value);
124
        }
125
    }
126
127
    public function benchContainsEnumeratorTrue()
128
    {
129
        foreach ($this->enumerators as $enumerator) {
130
            $this->fullSet->contains($enumerator);
131
        }
132
    }
133
134
    public function benchContainsValueTrue()
135
    {
136
        foreach ($this->values as $value) {
137
            $this->fullSet->contains($value);
138
        }
139
    }
140
141
    public function benchContainsEnumeratorFalse()
142
    {
143
        foreach ($this->enumerators as $enumerator) {
144
            $this->fullSet->contains($enumerator);
145
        }
146
    }
147
148
    public function benchContainsValueFalse()
149
    {
150
        foreach ($this->values as $value) {
151
            $this->fullSet->contains($value);
152
        }
153
    }
154
155
    public function benchIterateFull()
156
    {
157
        foreach ($this->fullSet as $enumerator) {
158
            $enumerator->getValue();
159
        }
160
    }
161
162
    public function benchIterateEmpty()
163
    {
164
        foreach ($this->emptySet as $enumerator) {
165
            $enumerator->getValue();
166
        }
167
    }
168
169
    public function benchCountFull()
170
    {
171
        $this->fullSet->count();
172
    }
173
174
    public function benchCountEmpty()
175
    {
176
        $this->emptySet->count();
177
    }
178
179
    public function benchIsEqual()
180
    {
181
        $this->fullSet->isEqual($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isEqual() 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...
182
    }
183
184
    public function benchIsSubset()
185
    {
186
        $this->fullSet->isEqual($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isEqual() 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...
187
    }
188
189
    public function benchIsSuperset()
190
    {
191
        $this->fullSet->isSuperset($this->fullSet);
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnum\EnumSet::isSuperset() 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...
192
    }
193
194
    public function benchUnion()
195
    {
196
        $this->fullSet->union($this->emptySet);
197
    }
198
199
    public function benchIntersect()
200
    {
201
        $this->fullSet->intersect($this->emptySet);
202
    }
203
204
    public function benchDiff()
205
    {
206
        $this->fullSet->diff($this->emptySet);
207
    }
208
209
    public function benchSymDiff()
210
    {
211
        $this->fullSet->symDiff($this->emptySet);
212
    }
213
214
    public function benchGetOrdinals()
215
    {
216
        $this->fullSet->getOrdinals();
217
    }
218
219
    public function benchGetValues()
220
    {
221
        $this->fullSet->getValues();
222
    }
223
224
    public function benchGetNames()
225
    {
226
        $this->fullSet->getNames();
227
    }
228
229
    public function benchGetEnumerators()
230
    {
231
        $this->fullSet->getEnumerators();
232
    }
233
}
234