Skip to content

Commit

Permalink
Merge pull request #202 from buggregator/hotfix/top-functions
Browse files Browse the repository at this point in the history
Fixes problem when some array keys are not existed
  • Loading branch information
butschster committed Jun 10, 2024
2 parents 1bf2d85 + 3598642 commit b6c6000
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function __invoke(FindTopFunctionsByUuid $query): array

foreach ($metrics as $metric) {
$field = 'excl_' . $metric;

if (!isset($functions[$edge->getCaller()][$field])) {
$functions[$edge->getCaller()][$field] = 0;
}

$functions[$edge->getCaller()][$field] -= $edge->getCost()->{$metric};

if ($functions[$edge->getCaller()][$field] < 0) {
Expand All @@ -76,7 +81,7 @@ public function __invoke(FindTopFunctionsByUuid $query): array
}

$sortMetric = $query->metric->value;
\usort($functions, static fn(array $a, array $b) => $b[$sortMetric] <=> $a[$sortMetric]);
\usort($functions, static fn(array $a, array $b) => ($b[$sortMetric] ?? 0) <=> ($a[$sortMetric] ?? 0));

$functions = \array_slice($functions, 0, $query->limit);

Expand Down

0 comments on commit b6c6000

Please sign in to comment.