| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 15 | final private static function getNames() |
|
| 21 | { |
||
| 22 | 15 | static $typeToName; |
|
| 23 | |||
| 24 | 15 | if (is_array($typeToName)) { |
|
| 25 | 15 | return $typeToName; |
|
| 26 | } |
||
| 27 | |||
| 28 | 6 | $tokenClassName = get_called_class(); |
|
| 29 | 6 | $reflection = new ReflectionClass($tokenClassName); |
|
| 30 | 6 | $constants = $reflection->getConstants(); |
|
| 31 | 6 | $typeToName = array_flip($constants); |
|
| 32 | |||
| 33 | 6 | return $typeToName; |
|
| 34 | } |
||
| 35 | |||
| 48 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClassto useselfinstead: