Completed
Push — feature/74 ( bd1a68...60c27e )
by Marc
02:46
created

EnumSet66Bench::benchContainsValueTrue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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