Completed
Push — feature/bench ( b33c92...39f38e )
by Marc
28:42 queued 22:54
created

EnumSet66Bench::benchSetBit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

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