From 735ace7ec6f5ff66d73b91baf8f6d36cbe3f8b76 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Mon, 6 Nov 2023 14:38:23 +0200 Subject: [PATCH] Fix PHP notice: Undefined index: samples (#128) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix PHP notice: Undefined index: samples collectHistograms() in the storage adapters does not define ['samples'] as the default array keys and as such a notice is thrown when the MetricFamilySamples::__construct($data) is called when no samples are available. * added space --------- Co-authored-by: Lukas Kämmerling --- src/Prometheus/MetricFamilySamples.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Prometheus/MetricFamilySamples.php b/src/Prometheus/MetricFamilySamples.php index ea4febf3..1cdb2b1a 100644 --- a/src/Prometheus/MetricFamilySamples.php +++ b/src/Prometheus/MetricFamilySamples.php @@ -40,8 +40,10 @@ public function __construct(array $data) $this->type = $data['type']; $this->help = $data['help']; $this->labelNames = $data['labelNames']; - foreach ($data['samples'] as $sampleData) { - $this->samples[] = new Sample($sampleData); + if (isset($data['samples'])) { + foreach ($data['samples'] as $sampleData) { + $this->samples[] = new Sample($sampleData); + } } }