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
IntegerTransformer
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 * Integer Number UiType Transformer.
15 *
16 * Handles UiType: integer_number.
17 * Read: formats integer with thousands separator for display.
18 * Write: casts to PHP int for safe PDO binding.
19 *
20 * @package App\Core\Engine\Application\Transformer
21 */
22final class IntegerTransformer implements UiTypeTransformerInterface
23{
24    /** {@inheritdoc} */
25    public function supports(string $uitypeName): bool
26    {
27        return $uitypeName === 'integer_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((int) $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 (int) $inputValue;
48    }
49}