MCPcopy Create free account
hub / github.com/Rello/analytics / extractSingleValues

Method extractSingleValues

lib/Datasource/ExternalJson.php:263–277  ·  view source on GitHub ↗

* Extracts single values for each path, handling arrays and scalars. */

($json, array $paths)

Source from the content-addressed store, hash-verified

261 * Extracts single values for each path, handling arrays and scalars.
262 */
263 private function extractSingleValues($json, array $paths): array {
264 $data = [];
265 foreach ($paths as $singlePath) {
266 $value = $this->get_nested_array_value($json, $singlePath);
267 $key = $this->getHeaderFromPath($singlePath);
268 if (is_array($value)) {
269 foreach ($value as $subKey => $subValue) {
270 $data[] = [$key, $subKey, $subValue];
271 }
272 } else {
273 $data[] = ['', $key, $value];
274 }
275 }
276 return $data;
277 }
278
279 /**
280 * Gets the last segment of a path separated by '/'.

Callers 1

jsonParserMethod · 0.95

Calls 2

getHeaderFromPathMethod · 0.95

Tested by

no test coverage detected