Passed
Push — master ( 0de292...c7f65a )
by Christian
02:22
created

OutputType::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Form\Type;
13
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\Form\DataTransformerInterface;
16
use Symfony\Component\Form\FormBuilderInterface;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
final class OutputType extends AbstractType implements DataTransformerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function buildForm(FormBuilderInterface $builder, array $options)
25
    {
26
        if ('' === $options['empty_data']) {
27
            $builder->addViewTransformer($this);
28
        }
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function configureOptions(OptionsResolver $resolver): void
35
    {
36
        $resolver->setDefaults([
37
            'compound'  => false,
38
            'required'  => false,
39
            'disabled'  => true,
40
        ]);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function transform($data)
47
    {
48
        return $data;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function reverseTransform($data)
55
    {
56
        return $data ?? '';
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getBlockPrefix()
63
    {
64
        return 'output';
65
    }
66
}
67