Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AmicronDecimalType | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| convertToPHPValue | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| convertToDatabaseValue | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| requiresSQLCommentHint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Doctrine; |
| 6 | |
| 7 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 8 | use Doctrine\DBAL\Types\DecimalType; |
| 9 | |
| 10 | /** |
| 11 | * Amicron decimal type: preserves full string precision for Firebird DECIMAL(15,6) columns. |
| 12 | * |
| 13 | * Doctrine's default DecimalType returns a string, but this type makes the contract |
| 14 | * explicit and ensures null-safety. Using string (not float) avoids IEEE 754 rounding |
| 15 | * errors on financial and weight values (e.g. ENDBETRAG, GEWICHT, WAEHRUNGSKURS). |
| 16 | * |
| 17 | * Usage in entity mapping: |
| 18 | * #[ORM\Column(name: 'endbetrag', type: 'amicron_decimal', precision: 15, scale: 6, nullable: true)] |
| 19 | * protected ?string $endbetrag = null; |
| 20 | */ |
| 21 | class AmicronDecimalType extends DecimalType |
| 22 | { |
| 23 | public const NAME = 'amicron_decimal'; |
| 24 | |
| 25 | #[\Override] |
| 26 | public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string |
| 27 | { |
| 28 | if ($value === null) { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | return (string) $value; |
| 33 | } |
| 34 | |
| 35 | #[\Override] |
| 36 | public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string |
| 37 | { |
| 38 | if ($value === null) { |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | return (string) $value; |
| 43 | } |
| 44 | |
| 45 | #[\Override] |
| 46 | public function requiresSQLCommentHint(AbstractPlatform $platform): bool |
| 47 | { |
| 48 | return true; |
| 49 | } |
| 50 | } |