From a94cfb47f8ad5bffe0479d948e14f8f7c3726d73 Mon Sep 17 00:00:00 2001 From: Pascal Chevrel Date: Sun, 3 Nov 2024 16:34:50 +0100 Subject: [PATCH] Sometimes we have missing data passed to the objet, deal with it --- src/pchevrel/BzKarma/Scoring.php | 9 +++++++-- tests/Unit/BzKarma/ScoringTest.php | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pchevrel/BzKarma/Scoring.php b/src/pchevrel/BzKarma/Scoring.php index f1b7afe..9663d81 100644 --- a/src/pchevrel/BzKarma/Scoring.php +++ b/src/pchevrel/BzKarma/Scoring.php @@ -140,8 +140,13 @@ class Scoring public function __construct(array $bugsDetails, int $release) { // Replace numeric keys by the real bug number - $bugsDetails = $bugsDetails['bugs']; - $this->bugsDetails = array_combine(array_column($bugsDetails, 'id'), $bugsDetails); + if (isset($bugsDetails['bugs'])) { + $bugsDetails = $bugsDetails['bugs']; + $this->bugsDetails = array_combine(array_column($bugsDetails, 'id'), $bugsDetails); + } else { + $this->bugsDetails = []; + } + $this->release = strval($release); $this->beta = strval($this->release + 1); $this->nightly = strval($this->release + 2); diff --git a/tests/Unit/BzKarma/ScoringTest.php b/tests/Unit/BzKarma/ScoringTest.php index 6843d77..74c9172 100644 --- a/tests/Unit/BzKarma/ScoringTest.php +++ b/tests/Unit/BzKarma/ScoringTest.php @@ -16,6 +16,10 @@ ->toBe('131'); expect($obj->nightly) ->toBe('132'); + + $obj = new Scoring([], 130); + expect($obj->bugsDetails) + ->toBe([]); }); test('Scoring->getBugScoreDetails()', function () use ($obj) {