| Conditions | 5 |
| Paths | 8 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public static function fromArray(array $objectArray) |
||
| 25 | { |
||
| 26 | $objectArray = static::preProcess($objectArray); |
||
| 27 | |||
| 28 | $object = new self(); |
||
| 29 | $reflectionObject = new ReflectionObject($object); |
||
| 30 | $props = $reflectionObject->getProperties(); |
||
| 31 | |||
| 32 | $missingFields = []; |
||
| 33 | foreach ($props as $prop) { |
||
| 34 | if (strpos($prop->getDocComment(), '@required') === false) { |
||
| 35 | continue; |
||
| 36 | } |
||
| 37 | $propName = $prop->getName(); |
||
| 38 | |||
| 39 | |||
| 40 | if (!isset($objectArray[$propName])) { |
||
| 41 | $missingFields[] = $propName; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | if (\count($missingFields) > 0) { |
||
| 46 | throw new ClientException('hydration: missing ['.implode(', ', $missingFields).']'); |
||
| 47 | } |
||
| 48 | |||
| 49 | self::getHydrator()->hydrate($objectArray, $object); |
||
| 50 | |||
| 51 | return $object; |
||
| 52 | } |
||
| 53 | |||
| 64 |