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

Method extractSingleValues

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

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