Completed
Push — symfony3-fqcn ( cea3b6...24b82c )
by Kamil
103:48 queued 86:45
created

StringFieldType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A render() 0 6 2
A configureOptions() 0 3 1
A getBlockPrefix() 0 4 1
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
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName()
57
    {
58
        return 'string';
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getBlockPrefix()
65
    {
66
        return 'string';
67
    }
68
}
69