Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
BigIntTransformer
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 transformRead
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 transformWrite
100.00% covered (success)
100.00%
3 / 3
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\Core\Engine\Application\Transformer;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Engine\Domain\Model\FieldMetadata;
12
13/**
14 * Big Integer (BIGINT) UiType Transformer.
15 *
16 * Handles UiType: bigint_number.
17 * Read: formats the big integer as a string (avoids PHP int overflow).
18 * Write: returns string representation safe for BIGINT PDO binding.
19 *
20 * @package App\Core\Engine\Application\Transformer
21 */
22final class BigIntTransformer implements UiTypeTransformerInterface
23{
24    /** {@inheritdoc} */
25    public function supports(string $uitypeName): bool
26    {
27        return $uitypeName === 'bigint_number';
28    }
29
30    /** {@inheritdoc} */
31    public function transformRead(mixed $rawValue, FieldMetadata $field): string
32    {
33        if ($rawValue === null) {
34            return '';
35        }
36
37        return number_format((float) $rawValue, 0, '.', ' ');
38    }
39
40    /** {@inheritdoc} */
41    public function transformWrite(mixed $inputValue, FieldMetadata $field): mixed
42    {
43        if ($inputValue === null || $inputValue === '') {
44            return null;
45        }
46
47        return (string) (int) $inputValue;
48    }
49}