| Total Complexity | 12 |
| Total Lines | 82 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 9 | final class Node implements NodeInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var |
||
| 13 | */ |
||
| 14 | private $value; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | private $meta = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param $value |
||
| 23 | * @param array $meta |
||
| 24 | */ |
||
| 25 | public function __construct($value, array $meta) |
||
| 26 | { |
||
| 27 | $this->value = $value; |
||
| 28 | $this->meta = $meta; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return array |
||
| 33 | */ |
||
| 34 | public function toArray() |
||
| 35 | { |
||
| 36 | $array = $this->meta + ['name' => $this->getName($this->value)]; |
||
| 37 | |||
| 38 | return $array; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param $value |
||
| 43 | * |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | private function getName($value) |
||
| 47 | { |
||
| 48 | if (is_object($value)) { |
||
| 49 | return get_class($value); |
||
| 50 | } |
||
| 51 | if (is_array($value)) { |
||
| 52 | return $this->getArrayName(); |
||
| 53 | } |
||
| 54 | |||
| 55 | return $this->getScalarName($value); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | private function getArrayName() |
||
| 62 | { |
||
| 63 | $name = 'array'; |
||
| 64 | |||
| 65 | return $name; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param $value |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | private function getScalarName($value) |
||
| 91 | } |
||
| 92 | } |
||
| 93 |