Skip to content

Commit

Permalink
Refactor rank calculation function in Trace
Browse files Browse the repository at this point in the history
Removed uneccessary comments and rearranged the order of types in the parameters within the rank calculation function. Further, the array returned was reformatted for improved readability. The process of incrementing the value of 'sameMetricValueCount' was also changed to the more standard unary operator (++$var).
  • Loading branch information
MarjovanLier committed Mar 5, 2024
1 parent d9e2d6c commit 382d784
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Trace.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ private static function rankByMetric(array $data, string $metric): array
* Calculates the rank for a given metric.
*
* @param array{ct: int, wt: int, cpu: int, mu: int, pmu: int, name: string} $item

Check notice on line 323 in src/Trace.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Trace.php#L323

Missing parameter comment
* @param string $metric
* @param int $currentRank
* @param int $sameMetricValueCount
* @param int|string|null $previousMetricValue
*
* @return array{int, int, int|string}
*/
Expand All @@ -333,15 +329,25 @@ private static function calculateRank(
string $metric,
int $currentRank,
int $sameMetricValueCount,
int|string|null $previousMetricValue
null|int|string $previousMetricValue
): array {
if ($previousMetricValue === null || $item[$metric] === $previousMetricValue) {
$sameMetricValueCount++;
return [$currentRank, $sameMetricValueCount, $item[$metric]];
++$sameMetricValueCount;

return [
$currentRank,
$sameMetricValueCount,
$item[$metric],

Check notice on line 340 in src/Trace.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Trace.php#L340

Array value not aligned correctly; expected 20 spaces but found 16
];
}

$currentRank += $sameMetricValueCount;
$sameMetricValueCount = 1;
return [$currentRank, $sameMetricValueCount, $item[$metric]];

return [
$currentRank,
$sameMetricValueCount,
$item[$metric],
];
}
}

0 comments on commit 382d784

Please sign in to comment.