| Conditions | 4 |
| Paths | 3 |
| Total Lines | 15 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public static function setProperty(&$entity, $property, $value) |
||
| 30 | { |
||
| 31 | // If magic method exists, try that first, else try property directly |
||
| 32 | if (method_exists($entity, '__set')) { |
||
| 33 | $entity->$property = $value; |
||
| 34 | } elseif (is_object($entity) && property_exists($entity, $property)) { |
||
| 35 | $entity->$property = $value; |
||
| 36 | } else { |
||
| 37 | $reflect = new \ReflectionProperty($entity, $property); |
||
| 38 | $oldAccess = $reflect->isPublic(); |
||
| 39 | $reflect->setAccessible(true); |
||
| 40 | $reflect->setValue($entity, $value); |
||
| 41 | $reflect->setAccessible($oldAccess); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |