Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
4 / 8 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DecimalEntity | |
50.00% |
4 / 8 |
|
20.00% |
1 / 5 |
16.00 | |
0.00% |
0 / 1 |
| toComma | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toDecimal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toFloat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toNullOrDecimal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| toNullOrFloat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Traits; |
| 6 | |
| 7 | trait 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 | } |