Skip to content

Commit

Permalink
Updated calculation service.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jan 21, 2025
1 parent 7eca10c commit 0dcc739
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
3 changes: 0 additions & 3 deletions src/Model/CalculationUpdateResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public function count(): int
return \count($this->results);
}

/**
* @psalm-api
*/
public function getResults(): array
{
return $this->results;
Expand Down
22 changes: 6 additions & 16 deletions src/Service/CalculationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ private function computeGroups(
float $user_margin,
?float $global_margin = null
): array {
$groups_amount = $this->round($this->getGroupsAmount($groups));
$groups_margin = $this->round($this->getGroupsMargin($groups));
$groups_amount = $this->getGroupsAmount($groups);
$groups_margin = $this->getGroupsMargin($groups);
$total_net = $groups_amount + $groups_margin;
$groups[self::ROW_TOTAL_GROUP] = $this->createGroup(
id: self::ROW_TOTAL_GROUP,
Expand Down Expand Up @@ -407,33 +407,23 @@ private function getGroupMargin(Group $group, float $amount): float
}

/**
* Gets groups total amount.
* Gets the sum of group's amount.
*
* @psalm-param GroupType[] $groups
*/
private function getGroupsAmount(array $groups): float
{
return \array_reduce(
$groups,
/** @psalm-param GroupType $group */
static fn (float $carry, array $group): float => $carry + $group['amount'],
0.0
);
return $this->round(\array_sum(\array_column($groups, 'amount')));
}

/**
* Gets groups total margin amount.
* Gets the sum of group's margin amount.
*
* @psalm-param GroupType[] $groups
*/
private function getGroupsMargin(array $groups): float
{
return \array_reduce(
$groups,
/** @psalm-param GroupType $group */
static fn (float $carry, array $group): float => $carry + $group['margin_amount'],
0.0
);
return $this->round(\array_sum(\array_column($groups, 'margin_amount')));
}

/**
Expand Down

0 comments on commit 0dcc739

Please sign in to comment.