Completed
Push — master ( fc73be...a0f602 )
by Kamil
04:16 queued 04:07
created

StringFieldType::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Component\Grid\FieldTypes;
13
14
use Sylius\Component\Grid\DataExtractor\DataExtractorInterface;
15
use Sylius\Component\Grid\Definition\Field;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * @author Paweł Jędrzejewski <[email protected]>
20
 */
21
final class StringFieldType implements FieldTypeInterface
22
{
23
    /**
24
     * @var DataExtractorInterface
25
     */
26
    private $dataExtractor;
27
28
    /**
29
     * @param DataExtractorInterface $dataExtractor
30
     */
31
    public function __construct(DataExtractorInterface $dataExtractor)
32
    {
33
        $this->dataExtractor = $dataExtractor;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function render(Field $field, $data, array $options)
40
    {
41
        $value = $this->dataExtractor->get($field, $data);
42
43
        return is_string($value) ? htmlspecialchars($value) : $value;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function configureOptions(OptionsResolver $resolver)
50
    {
51
    }
52
}
53