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

Method extractSingleValues

lib/Datasource/ExternalJson.php:262–276  ·  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

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