NullToEmptyTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reverseTransform() 0 3 1
A transform() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeBundle\Form\DataTransformer;
15
16
use Symfony\Component\Form\DataTransformerInterface;
17
18
/**
19
 * Workaround for Symfony bug #5906
20
 * @see https://github.com/symfony/symfony/issues/5906
21
 * @author b.b3rn4ard
22
 * @see http://stackoverflow.com/a/28889445/2600812
23
 * Class NullToEmptyTransformer
24
 */
25
class NullToEmptyTransformer implements DataTransformerInterface
26
{
27
    /**
28
     * Does not transform anything.
29
     *
30
     * @param string|null $value
31
     * @return string
32
     */
33
    public function transform(mixed $value): mixed
34
    {
35
        return $value;
36
    }
37
38
    /**
39
     * Transforms a null value to an empty string.
40
     *
41
     * @param string $value
42
     * @return string
43
     */
44
    public function reverseTransform(mixed $value): mixed
45
    {
46
        return $value ?? '';
47
    }
48
}
49