Completed
Pull Request — master (#87)
by Marc
15:48 queued 09:49
created

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