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

EnumBench::benchIsByEnumerator()   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 MabeEnumTest\TestAsset\Enum66;
6
7
/**
8
 * Benchmark of abstract class Enum tested with enumeration of 66 enumerators.
9
 *
10
 * @BeforeMethods({"init"})
11
 * @Revs(2500)
12
 * @Iterations(25)
13
 */
14
class EnumBench
15
{
16
    /**
17
     * @var string[]
18
     */
19
    private $names;
20
21
    /**
22
     * @var mixed[]
23
     */
24
    private $values;
25
26
    /**
27
     * @var int[]
28
     */
29
    private $ordinals;
30
31
    /**
32
     * @var Enum66[]
33
     */
34
    private $enumerators;
35
36
    /**
37
     * Will be called before every subject
38
     */
39
    public function init()
40
    {
41
        $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...
42
        $this->values      = Enum66::getValues();
43
        $this->ordinals    = Enum66::getOrdinals();
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
47
    public function benchGetName()
48
    {
49
        foreach ($this->enumerators as $enumerator) {
50
            $enumerator->getName();
51
        }
52
    }
53
54
    public function benchGetValue()
55
    {
56
        foreach ($this->enumerators as $enumerator) {
57
            $enumerator->getValue();
0 ignored issues
show
Unused Code introduced by
The call to the method MabeEnumTest\TestAsset\Enum66::getValue() 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...
58
        }
59
    }
60
61
    public function benchGetOrdinal()
62
    {
63
        foreach ($this->enumerators as $enumerator) {
64
            $enumerator->getOrdinal();
65
        }
66
    }
67
68
    public function benchIsByEnumerator()
69
    {
70
        foreach ($this->enumerators as $enumerator) {
71
            $enumerator->is($enumerator);
72
        }
73
    }
74
75
    public function benchIsByValue()
76
    {
77
        foreach ($this->enumerators as $enumerator) {
78
            $enumerator->is($enumerator->getValue());
79
        }
80
    }
81
82
    public function benchGetConstants()
83
    {
84
        Enum66::getConstants();
85
    }
86
87
    public function benchGetValues()
88
    {
89
        Enum66::getValues();
90
    }
91
92
    public function benchGetNames()
93
    {
94
        Enum66::getNames();
95
    }
96
97
    public function benchGetOrdinals()
98
    {
99
        Enum66::getOrdinals();
100
    }
101
102
    public function benchGetEnumerators()
103
    {
104
        Enum66::getEnumerators();
105
    }
106
107
    public function benchByValue()
108
    {
109
        foreach ($this->values as $value) {
110
            Enum66::byValue($value);
111
        }
112
    }
113
114
    public function benchByName()
115
    {
116
        foreach ($this->names as $name) {
117
            Enum66::byName($name);
118
        }
119
    }
120
121
    public function benchByOrdinal()
122
    {
123
        foreach ($this->ordinals as $ord) {
124
            Enum66::byOrdinal($ord);
125
        }
126
    }
127
128
    public function benchGetByValues()
129
    {
130
        foreach ($this->values as $value) {
131
            Enum66::get($value);
132
        }
133
    }
134
135
    public function benchGetByEnumerator()
136
    {
137
        foreach ($this->enumerators as $enumerator) {
138
            Enum66::get($enumerator);
139
        }
140
    }
141
142
    public function benchGetByCallStatic()
143
    {
144
        foreach ($this->names as $name) {
145
            Enum66::$name();
146
        }
147
    }
148
149
    public function benchHasByEnumerator()
150
    {
151
        foreach ($this->enumerators as $enumerator) {
152
            Enum66::has($enumerator);
153
        }
154
    }
155
156
    public function benchHasByValue()
157
    {
158
        foreach ($this->values as $value) {
159
            Enum66::has($value);
160
        }
161
    }
162
}
163