1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* GpsLab component. |
5
|
|
|
* |
6
|
|
|
* @author Peter Gribanov <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2017, Peter Gribanov |
8
|
|
|
* @license http://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace GpsLab\Component\Enum\Bench\Compare\Operation; |
12
|
|
|
|
13
|
|
|
use GpsLab\Component\Enum\Bench\Compare\CompareEnumBench; |
14
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcExp; |
15
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\AbcRef; |
16
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\DefRef; |
17
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcHappyTypes; |
18
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMarcMabe; |
19
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\AbcMyClabs; |
20
|
|
|
use GpsLab\Component\Enum\Tests\Fixture\Enum\Rival\DefMarcMabe; |
21
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Iterations; |
22
|
|
|
use PhpBench\Benchmark\Metadata\Annotations\Revs; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @Revs(2500) |
26
|
|
|
* @Iterations(25) |
27
|
|
|
*/ |
28
|
|
|
class CompareToStringEnumBench implements CompareEnumBench |
29
|
|
|
{ |
30
|
|
|
public function benchReflectionEnum() |
31
|
|
|
{ |
32
|
|
|
$a = (string) AbcRef::A(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function benchReflectionEnumNoMagic() |
36
|
|
|
{ |
37
|
|
|
$d = (string) DefRef::byValue(DefRef::D); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function benchExplicitEnum() |
41
|
|
|
{ |
42
|
|
|
$a = (string) AbcExp::byValue(AbcExp::A); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function benchMyCLabsEnum() |
46
|
|
|
{ |
47
|
|
|
$a = (string) AbcMyClabs::A(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function benchMabeEnum() |
51
|
|
|
{ |
52
|
|
|
$a = (string) AbcMarcMabe::A(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function benchMabeNoMagicEnum() |
56
|
|
|
{ |
57
|
|
|
$d = (string) DefMarcMabe::byValue(DefMarcMabe::D); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function benchHappyTypesEnum() |
61
|
|
|
{ |
62
|
|
|
$a = (string) AbcHappyTypes::A(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.