Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
RoundingMethod
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 round
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Tax\Domain\ValueObject;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Enumeration representing the mathematical rounding method.
13 */
14enum RoundingMethod: string
15{
16    case HALF_UP = 'half_up';
17    case HALF_EVEN = 'half_even';
18
19    /**
20     * Round a float value according to the configured rounding method and precision.
21     */
22    public function round(float $value, int $precision = 2): float
23    {
24        $mode = match ($this) {
25            self::HALF_UP => PHP_ROUND_HALF_UP,
26            self::HALF_EVEN => PHP_ROUND_HALF_EVEN,
27        };
28
29        return round($value, $precision, $mode);
30    }
31}