| Conditions | 3 |
| Paths | 3 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 28 | 6 | private static function formatDecimalNumber(string $number, array $attributes): string |
|
| 29 | { |
||
| 30 | 6 | if ($attributes['scale'] > $attributes['precision']) { |
|
| 31 | 1 | throw MappingException::forInvalidAttributeValue( |
|
| 32 | 1 | 'scale', |
|
| 33 | 1 | $attributes['scale'], |
|
| 34 | 1 | 'Attribute `scale` must be lower than `precision`.' |
|
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | 5 | $parts = explode('.', $number); |
|
| 39 | 5 | $decimals = $attributes['precision'] - $attributes['scale']; |
|
| 40 | |||
| 41 | 5 | if (strlen($parts[0]) > $decimals) { |
|
| 42 | 1 | $parts[0] = str_repeat('9', $decimals); |
|
| 43 | } |
||
| 44 | |||
| 45 | 5 | $number = $parts[0] . '.' . ($parts[1] ?? ''); |
|
| 46 | |||
| 47 | 5 | return bcadd($number, '0', $attributes['scale']); |
|
| 48 | } |
||
| 50 |