@@ -22,19 +22,19 @@ |
||
22 | 22 | */ |
23 | 23 | final class ToArrayConverter implements ConverterContract |
24 | 24 | { |
25 | - /** |
|
26 | - * Returns array representation of the object. |
|
27 | - * |
|
28 | - * @param object $obj Object to be converted |
|
29 | - * @param array $config Converter config array to be used for this object (based on exact class |
|
30 | - * name match or inheritance). |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array |
|
35 | - { |
|
36 | - Validator::assertIsObject('obj', $obj); |
|
25 | + /** |
|
26 | + * Returns array representation of the object. |
|
27 | + * |
|
28 | + * @param object $obj Object to be converted |
|
29 | + * @param array $config Converter config array to be used for this object (based on exact class |
|
30 | + * name match or inheritance). |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array |
|
35 | + { |
|
36 | + Validator::assertIsObject('obj', $obj); |
|
37 | 37 | |
38 | - return $obj->toArray(); |
|
39 | - } |
|
38 | + return $obj->toArray(); |
|
39 | + } |
|
40 | 40 | } |
@@ -40,20 +40,20 @@ |
||
40 | 40 | $array = $original; |
41 | 41 | foreach ($merging as $m_key => $m_val) { |
42 | 42 | if (\array_key_exists($m_key, $original)) { |
43 | - $orig_type = \gettype($original[ $m_key ]); |
|
43 | + $orig_type = \gettype($original[$m_key]); |
|
44 | 44 | $m_type = \gettype($m_val); |
45 | 45 | if ($orig_type !== $m_type) { |
46 | 46 | throw new Ex\IncompatibleTypeException( |
47 | 47 | "Incompatible types. Cannot merge {$m_type} into {$orig_type} (key '{$m_key}')."); |
48 | 48 | } |
49 | 49 | |
50 | - if (\is_array($merging[ $m_key ])) { |
|
51 | - $array[ $m_key ] = static::mergeConfig($original[ $m_key ], $m_val); |
|
50 | + if (\is_array($merging[$m_key])) { |
|
51 | + $array[$m_key] = static::mergeConfig($original[$m_key], $m_val); |
|
52 | 52 | } else { |
53 | - $array[ $m_key ] = $m_val; |
|
53 | + $array[$m_key] = $m_val; |
|
54 | 54 | } |
55 | 55 | } else { |
56 | - $array[ $m_key ] = $m_val; |
|
56 | + $array[$m_key] = $m_val; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $worker = new $cfg[ RB::KEY_HANDLER ](); |
148 | 148 | $result = $worker->convert($data, $cfg); |
149 | 149 | $result = $cfg[ RB::KEY_KEY ] === null ? $result : [$cfg[ RB::KEY_KEY ] => $result]; |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | 152 | if ($result === null && \is_array($data)) { |
153 | 153 | $cfg = $this->getPrimitiveMappingConfigOrThrow($data); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | "Missing '{$key_name}' entry in '{$class_name}' class mapping config."); |
226 | 226 | } |
227 | 227 | |
228 | - Validator::assertIsType(RB::KEY_KEY, $class_config[$key_name], $allowed_types); |
|
228 | + Validator::assertIsType(RB::KEY_KEY, $class_config[$key_name], $allowed_types); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $result = null; |
61 | 61 | |
62 | 62 | $type = \gettype($data); |
63 | - $result = $this->primitives[ $type ] ?? null; |
|
63 | + $result = $this->primitives[$type] ?? null; |
|
64 | 64 | |
65 | 65 | if ($result === null) { |
66 | 66 | throw new Ex\ConfigurationNotFoundException( |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | $cls = \get_class($data); |
93 | 93 | if ($cls !== false) { |
94 | 94 | if (\array_key_exists($cls, $this->classes)) { |
95 | - $result = $this->classes[ $cls ]; |
|
95 | + $result = $this->classes[$cls]; |
|
96 | 96 | $debug_result = 'exact config match'; |
97 | 97 | } else { |
98 | 98 | // no exact match, then lets try with `instanceof` |
99 | 99 | foreach (\array_keys($this->classes) as $class_name) { |
100 | 100 | if ($data instanceof $class_name) { |
101 | - $result = $this->classes[ $class_name ]; |
|
101 | + $result = $this->classes[$class_name]; |
|
102 | 102 | $debug_result = "subclass of {$class_name}"; |
103 | 103 | break; |
104 | 104 | } |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | |
145 | 145 | if ($result === null && \is_object($data)) { |
146 | 146 | $cfg = $this->getClassMappingConfigOrThrow($data); |
147 | - $worker = new $cfg[ RB::KEY_HANDLER ](); |
|
147 | + $worker = new $cfg[RB::KEY_HANDLER](); |
|
148 | 148 | $result = $worker->convert($data, $cfg); |
149 | - $result = $cfg[ RB::KEY_KEY ] === null ? $result : [$cfg[ RB::KEY_KEY ] => $result]; |
|
149 | + $result = $cfg[RB::KEY_KEY] === null ? $result : [$cfg[RB::KEY_KEY] => $result]; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | if ($result === null && \is_array($data)) { |
@@ -154,12 +154,12 @@ discard block |
||
154 | 154 | |
155 | 155 | $result = $this->convertArray($data); |
156 | 156 | if (!Util::isArrayWithNonNumericKeys($data)) { |
157 | - $result = [$cfg[ RB::KEY_KEY ] => $result]; |
|
157 | + $result = [$cfg[RB::KEY_KEY] => $result]; |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
161 | 161 | if (\is_bool($data) || \is_float($data) || \is_int($data) || \is_string($data)) { |
162 | - $result = [$this->getPrimitiveMappingConfigOrThrow($data)[ RB::KEY_KEY ] => $data]; |
|
162 | + $result = [$this->getPrimitiveMappingConfigOrThrow($data)[RB::KEY_KEY] => $data]; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $result; |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | |
180 | 180 | foreach ($data as $key => $val) { |
181 | 181 | if (\is_array($val)) { |
182 | - $data[ $key ] = $this->convertArray($val); |
|
182 | + $data[$key] = $this->convertArray($val); |
|
183 | 183 | } elseif (\is_object($val)) { |
184 | 184 | $cfg = $this->getClassMappingConfigOrThrow($val); |
185 | - $worker = new $cfg[ RB::KEY_HANDLER ](); |
|
185 | + $worker = new $cfg[RB::KEY_HANDLER](); |
|
186 | 186 | $converted_data = $worker->convert($val, $cfg); |
187 | - $data[ $key ] = $converted_data; |
|
187 | + $data[$key] = $converted_data; |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 |