Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractStringTransformer
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 transformRead
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 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 * Base Abstract String Transformer.
15 *
16 * Provides shared string sanitization and empty checking for string-based UiTypes.
17 *
18 * @package App\Core\Engine\Application\Transformer
19 */
20abstract class AbstractStringTransformer implements UiTypeTransformerInterface
21{
22    /** {@inheritdoc} */
23    public function transformRead(mixed $rawValue, FieldMetadata $field): string
24    {
25        if ($rawValue === null || $rawValue === '') {
26            return '';
27        }
28
29        return trim((string) $rawValue);
30    }
31
32    /** {@inheritdoc} */
33    public function transformWrite(mixed $inputValue, FieldMetadata $field): mixed
34    {
35        if ($inputValue === null || $inputValue === '') {
36            return null;
37        }
38
39        return trim(strip_tags((string) $inputValue));
40    }
41}