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

Method extractSingleValues

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

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