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

EnumSet32Bench::benchContainsValueFalse()   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\Enum32;
7
8
/**
9
 * Benchmark of EnumSet used with an enumeration of 32 enumerators.
10
 * (The internal bitset could be both an integer and a binary string)
11
 *
12
 * @BeforeMethods({"init"})
13
 * @Revs(2000)
14
 * @Iterations(25)
15
 */
16
class EnumSet32Bench
17
{
18
    /**
19
     * @var mixed[]
20
     */
21
    private $values;
22
23
    /**
24
     * @var Enum32[]
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      = Enum32::getValues();
44
        $this->enumerators = Enum32::getEnumerators();
0 ignored issues
show
Documentation Bug introduced by
It seems like \MabeEnumTest\TestAsset\Enum32::getEnumerators() of type array<integer,object<MabeEnum\Enum>> is incompatible with the declared type array<integer,object<Mab...Test\TestAsset\Enum32>> 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(Enum32::class);
47
        $this->fullSet  = new EnumSet(Enum32::class);
48
        foreach ($this->enumerators as $enumerator) {
49
            $this->fullSet->attach($enumerator);
50
        }
51
    }
52
53
    public function benchAttachEnumerator()
54
    {
55
        foreach ($this->enumerators as $enumerator) {
56
            $this->emptySet->attach($enumerator);
57
        }
58
    }
59
60
    public function benchAttachValue()
61
    {
62
        foreach ($this->values as $value) {
63
            $this->emptySet->attach($value);
64
        }
65
    }
66
67
    public function benchDetachEnumerator()
68
    {
69
        foreach ($this->enumerators as $enumerator) {
70
            $this->fullSet->detach($enumerator);
71
        }
72
    }
73
74
    public function benchDetachValue()
75
    {
76
        foreach ($this->values as $value) {
77
            $this->fullSet->detach($value);
78
        }
79
    }
80
81
    public function benchContainsEnumeratorTrue()
82
    {
83
        foreach ($this->enumerators as $enumerator) {
84
            $this->fullSet->contains($enumerator);
85
        }
86
    }
87
88
    public function benchContainsEnumeratorFalse()
89
    {
90
        foreach ($this->enumerators as $enumerator) {
91
            $this->fullSet->contains($enumerator);
92
        }
93
    }
94
95
    public function benchContainsValueTrue()
96
    {
97
        foreach ($this->values as $value) {
98
            $this->fullSet->contains($value);
99
        }
100
    }
101
102
    public function benchContainsValueFalse()
103
    {
104
        foreach ($this->values as $value) {
105
            $this->fullSet->contains($value);
106
        }
107
    }
108
109
    public function benchIterateFull()
110
    {
111
        foreach ($this->fullSet as $enumerator) {
112
            $enumerator->getValue();
113
        }
114
    }
115
116
    public function benchIterateEmpty()
117
    {
118
        foreach ($this->emptySet as $enumerator) {
119
            $enumerator->getValue();
120
        }
121
    }
122
123
    public function benchCountFull()
124
    {
125
        $this->fullSet->count();
126
    }
127
128
    public function benchCountEmpty()
129
    {
130
        $this->emptySet->count();
131
    }
132
133
    public function benchIsEqual()
134
    {
135
        $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...
136
    }
137
138
    public function benchIsSubset()
139
    {
140
        $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...
141
    }
142
143
    public function benchIsSuperset()
144
    {
145
        $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...
146
    }
147
148
    public function benchUnion()
149
    {
150
        $this->fullSet->union($this->emptySet);
151
    }
152
153
    public function benchIntersect()
154
    {
155
        $this->fullSet->intersect($this->emptySet);
156
    }
157
158
    public function benchDiff()
159
    {
160
        $this->fullSet->diff($this->emptySet);
161
    }
162
163
    public function benchSymDiff()
164
    {
165
        $this->fullSet->symDiff($this->emptySet);
166
    }
167
168
    public function benchGetOrdinals()
169
    {
170
        $this->fullSet->getOrdinals();
171
    }
172
173
    public function benchGetValues()
174
    {
175
        $this->fullSet->getValues();
176
    }
177
178
    public function benchGetNames()
179
    {
180
        $this->fullSet->getNames();
181
    }
182
183
    public function benchGetEnumerators()
184
    {
185
        $this->fullSet->getEnumerators();
186
    }
187
}
188