| Conditions | 4 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 21 | public static function getAnnotations($class, $value) |
||
| 22 | { |
||
| 23 | $propertyReflect = new \ReflectionProperty($class, $value); |
||
| 24 | $doc = $propertyReflect->getDocComment(); |
||
| 25 | if (!preg_match_all('#@(.*?)\n#s', $doc, $annotations)) { |
||
| 26 | return false; |
||
| 27 | }; |
||
| 28 | $annotations = $annotations[1]; |
||
| 29 | $return = []; |
||
| 30 | foreach ($annotations as $annotation) { |
||
| 31 | list($k, $v) = array_pad(explode(' ', $annotation, 2), 2, null); |
||
| 32 | if (array_key_exists($k, static::$map)) { |
||
|
|
|||
| 33 | $type = static::$map[$k]; |
||
| 34 | $v = Jasny\TypeCast::value($v)->to($type); |
||
| 35 | } |
||
| 36 | |||
| 37 | $return[$k] = $v; |
||
| 38 | } |
||
| 39 | |||
| 40 | return $return; |
||
| 41 | } |
||
| 42 | } |
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: