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

Method extractSingleValues

lib/Datasource/LocalJson.php:228–242  ·  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

226 * Extracts single values for each path, handling arrays and scalars.
227 */
228 private function extractSingleValues($json, array $paths): array {
229 $data = [];
230 foreach ($paths as $singlePath) {
231 $value = $this->get_nested_array_value($json, $singlePath);
232 $key = $this->getHeaderFromPath($singlePath);
233 if (is_array($value)) {
234 foreach ($value as $subKey => $subValue) {
235 $data[] = [$key, $subKey, $subValue];
236 }
237 } else {
238 $data[] = ['', $key, $value];
239 }
240 }
241 return $data;
242 }
243
244 /**
245 * 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