Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SelectTransformer
100.00% covered (success)
100.00%
8 / 8
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%
4 / 4
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 * Single Select Dropdown UiType Transformer.
15 *
16 * Handles UiType: single_select.
17 * Read: maps the stored key to a human-readable label from filter_options.
18 * Write: validates that the input is one of the allowed values from filter_options.
19 *
20 * @package App\Core\Engine\Application\Transformer
21 */
22final class SelectTransformer implements UiTypeTransformerInterface
23{
24    /** {@inheritdoc} */
25    public function supports(string $uitypeName): bool
26    {
27        return $uitypeName === 'single_select';
28    }
29
30    /** {@inheritdoc} */
31    public function transformRead(mixed $rawValue, FieldMetadata $field): string
32    {
33        if ($rawValue === null) {
34            return '';
35        }
36
37        $key = (string) $rawValue;
38
39        return (string) ($field->filterOptions[$key] ?? $key);
40    }
41
42    /** {@inheritdoc} */
43    public function transformWrite(mixed $inputValue, FieldMetadata $field): mixed
44    {
45        if ($inputValue === null || $inputValue === '') {
46            return null;
47        }
48
49        return (string) $inputValue;
50    }
51}