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

EnumBench::benchGetNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
 * @BeforeClassMethods({"initClass"})
11
 * @Revs(2500)
12
 * @Iterations(25)
13
 */
14
class EnumBench
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
     * Initialize class
43
     */
44
    public static function initClass()
45
    {
46
        // initialize the enum to make sure the initialization process
47
        // will not effect the benchmark
48
        self::$constants   = Enum66::getConstants();
49
        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...
50
        self::$values      = Enum66::getValues();
51
        self::$ordinals    = Enum66::getOrdinals();
52
        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...
53
    }
54
55
    public function benchGetName()
56
    {
57
        foreach (self::$enumerators as $enumerator) {
58
            $enumerator->getName();
59
        }
60
    }
61
62
    public function benchGetValue()
63
    {
64
        foreach (self::$enumerators as $enumerator) {
65
            $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...
66
        }
67
    }
68
69
    public function benchGetOrdinal()
70
    {
71
        foreach (self::$enumerators as $enumerator) {
72
            $enumerator->getOrdinal();
73
        }
74
    }
75
76
    public function benchIsByEnumerator()
77
    {
78
        foreach (self::$enumerators as $enumerator) {
79
            $enumerator->is($enumerator);
80
        }
81
    }
82
83
    public function benchIsByValue()
84
    {
85
        foreach (self::$enumerators as $enumerator) {
86
            $enumerator->is($enumerator->getValue());
87
        }
88
    }
89
90
    public function benchGetConstants()
91
    {
92
        Enum66::getConstants();
93
    }
94
95
    public function benchGetValues()
96
    {
97
        Enum66::getValues();
98
    }
99
100
    public function benchGetNames()
101
    {
102
        Enum66::getNames();
103
    }
104
105
    public function benchGetOrdinals()
106
    {
107
        Enum66::getOrdinals();
108
    }
109
110
    public function benchGetEnumerators()
111
    {
112
        Enum66::getEnumerators();
113
    }
114
115
    public function benchByValue()
116
    {
117
        foreach (self::$values as $value) {
118
            Enum66::byValue($value);
119
        }
120
    }
121
122
    public function benchByName()
123
    {
124
        foreach (self::$names as $name) {
125
            Enum66::byName($name);
126
        }
127
    }
128
129
    public function benchByOrdinal()
130
    {
131
        foreach (self::$ordinals as $ord) {
132
            Enum66::byOrdinal($ord);
133
        }
134
    }
135
136
    public function benchGetByValues()
137
    {
138
        foreach (self::$values as $value) {
139
            Enum66::get($value);
140
        }
141
    }
142
143
    public function benchGetByEnumerator()
144
    {
145
        foreach (self::$enumerators as $enumerator) {
146
            Enum66::get($enumerator);
147
        }
148
    }
149
150
    public function benchGetByCallStatic()
151
    {
152
        foreach (self::$names as $name) {
153
            Enum66::$name();
154
        }
155
    }
156
157
    public function benchHasByEnumerator()
158
    {
159
        foreach (self::$enumerators as $enumerator) {
160
            Enum66::has($enumerator);
161
        }
162
    }
163
164
    public function benchHasByValue()
165
    {
166
        foreach (self::$values as $value) {
167
            Enum66::has($value);
168
        }
169
    }
170
}
171