HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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);
    }
}