Skip to content

Commit

Permalink
Sometimes we have missing data passed to the objet, deal with it
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Nov 3, 2024
1 parent 72100f2 commit a94cfb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pchevrel/BzKarma/Scoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/BzKarma/ScoringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a94cfb4

Please sign in to comment.