| Conditions | 8 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 8.0046 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 11 | public function __construct($array, $fieldName = "value") |
|
| 22 | { |
||
| 23 | |||
| 24 | 11 | if (empty($array)) { |
|
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | 11 | if (!is_array($array)) { |
|
| 29 | 1 | throw new UnexpectedValueException("You need to pass an array"); |
|
| 30 | } |
||
| 31 | |||
| 32 | 10 | $this->array = array(); |
|
| 33 | |||
| 34 | 10 | foreach ($array as $key => $value) { |
|
| 35 | 10 | if (is_array($value)) { |
|
| 36 | 2 | $this->array[$key] = $value; |
|
| 37 | 10 | } elseif (!is_object($value)) { |
|
| 38 | 4 | $this->array[$key] = array($fieldName => $value); |
|
| 39 | 4 | } else { |
|
| 40 | 4 | $result = array("__class" => get_class($value)); |
|
| 41 | 4 | $methods = get_class_methods($value); |
|
| 42 | 4 | foreach ($methods as $method) { |
|
| 43 | 4 | if (strpos($method, "get") === 0) { |
|
| 44 | 2 | $result[substr($method, 3)] = $value->{$method}(); |
|
| 45 | 2 | } |
|
| 46 | 4 | } |
|
| 47 | 4 | $this->array[$key] = $result; |
|
| 48 | 4 | $props = get_object_vars($value); |
|
| 49 | 4 | $this->array[$key] += $props; |
|
| 50 | } |
||
| 51 | 10 | } |
|
| 52 | 10 | } |
|
| 53 | |||
| 64 |