Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
DecimalEntity
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 5
72
0.00% covered (danger)
0.00%
0 / 1
 toComma
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 toDecimal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toFloat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toNullOrDecimal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 toNullOrFloat
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Satag\AmicronEntityBundle\Traits;
6
7trait DecimalEntity
8{
9    private function toComma(float|int|null $value, int $precision = 6): string
10    {
11        $ret = str_replace('.', ',', (string) round((float) $value, $precision));
12        if (!str_contains($ret, ',')) {
13            $ret .= ',000000';
14        }
15
16        return $ret;
17    }
18
19    private function toDecimal(float|int|null $value, int $precision = 6): string
20    {
21        return (string) round((float) $value, $precision);
22    }
23
24    private function toFloat(float|int|null $value, int $precision = 6): float
25    {
26        return round((float) $value, $precision);
27    }
28
29    private function toNullOrDecimal(float|int|null $value, int $precision = 6): ?string
30    {
31        return $value ? (string) round((float) $value, $precision) : null;
32    }
33
34    private function toNullOrFloat(float|int|null $value, int $precision = 6): ?float
35    {
36        return $value === null ? null : round((float) $value, $precision);
37    }
38}