0, 'element_count' => 0, 'string_byte_total' => 0, 'truncated' => false); self::walk($payload, 0, $stats); return $stats; } /** * @param mixed $value * @param array{depth: int, element_count: int, string_byte_total: int, truncated: bool} $stats */ private static function walk($value, int $currentDepth, array &$stats): void { if ($stats['truncated']) { return; } $stats['depth'] = max($stats['depth'], $currentDepth); if ($currentDepth >= self::MAX_DEPTH) { $stats['truncated'] = true; return; } if (is_string($value)) { $stats['string_byte_total'] += strlen($value); return; } $children = null; if (is_array($value)) { $children = $value; } else if (is_object($value)) { $children = get_object_vars($value); } if ($children === null) { return; } foreach ($children as $child) { $stats['element_count']++; if ($stats['element_count'] >= self::MAX_ELEMENTS) { $stats['truncated'] = true; return; } self::walk($child, $currentDepth + 1, $stats); } } }