File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Finance/RoundingService.php
<?php declare(strict_types=1);
namespace App\Finance;
/**
* Class RoundingService
*
* All rounding operations MUST pass through this class.
* So we can ensure that the only rounding errors, if any, occur here.
*
* @package App\Finance
*/
class RoundingService
{
public static function RoundVat(float $value): int {
return self::RoundType($value, 'vat_total');
}
public static function Round(float $value): int {
return self::RoundType($value, 'general');
}
private static function RoundType(float $value, string $type): int {
$roundingType = config('financial.cent_rounding.'.$type, null);
if(!$roundingType) throw new \InvalidArgumentException($type.' is not found in the financial config file, cent_rounding array.');
return (int) round($value, 0, $roundingType);
}
}