| Conditions | 9 |
| Paths | 12 |
| Total Lines | 42 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 23.7415 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 3 | public function hydrate($data, $object, HydratorContextInterface $context) |
|
| 13 | { |
||
| 14 | 3 | foreach ($data as $key => $value) { |
|
| 15 | 3 | if (null === $property = $context->getProperty($key)) { |
|
| 16 | continue; |
||
| 17 | } |
||
| 18 | 3 | if ($property->isIgnored()) { |
|
| 19 | continue; |
||
| 20 | } |
||
| 21 | 3 | $setter = $property->getSetter(); |
|
| 22 | 3 | $caller = array($object, $setter); |
|
| 23 | 3 | if (!method_exists($object, $setter)) { |
|
| 24 | 3 | if (!array_key_exists($key, get_object_vars($object))) { |
|
| 25 | throw new HydratationException(sprintf( |
||
| 26 | "Undefined setter method %s::%s for property '%s'", |
||
| 27 | get_class($object), |
||
| 28 | $setter, |
||
| 29 | $key |
||
| 30 | )); |
||
| 31 | } |
||
| 32 | $caller = function ($value) use ($object, $key) { |
||
| 33 | 3 | $object->$key = $value; |
|
| 34 | 3 | }; |
|
| 35 | } |
||
| 36 | 3 | if (null !== $subContext = $property->getContext()) { |
|
| 37 | if (!is_array($value)) { |
||
| 38 | continue; |
||
| 39 | } |
||
| 40 | $subClass = $subContext->getClass(); |
||
| 41 | if (!class_exists($subClass)) { |
||
| 42 | throw new HydratationException(sprintf( |
||
| 43 | "Class %s does not exist for property '%s'", |
||
| 44 | $subClass, |
||
| 45 | $key |
||
| 46 | )); |
||
| 47 | } |
||
| 48 | $subObject = new $subClass; |
||
| 49 | $value = $this->hydrate($value, $subObject, $subContext); |
||
| 50 | } |
||
| 51 | 3 | call_user_func_array($caller, array($value)); |
|
| 52 | } |
||
| 53 | 3 | return $object; |
|
| 54 | } |
||
| 56 |