Completed
Push — master ( 1fe708...6360f1 )
by Arnaud
16s queued 12s
created

TextView::getDataTransformer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Field\View;
6
7
use Closure;
8
use LAG\AdminBundle\Exception\Exception;
9
use LAG\AdminBundle\Exception\Field\ViewException;
10
11
class TextView implements View
12
{
13
    private string $name;
14
    private array $options;
15
    private ?Closure $dataTransformer;
16
17 1
    public function __construct(string $name, array $options = [], ?Closure $dataTransformer = null)
18
    {
19 1
        $this->name = $name;
20 1
        $this->options = $options;
21 1
        $this->dataTransformer = $dataTransformer;
22 1
    }
23
24
    public function getName(): string
25
    {
26
        return $this->name;
27
    }
28
29
    public function getOptions(): array
30
    {
31
        return $this->options;
32
    }
33
34
    public function getOption(string $name)
35
    {
36
        if (!\array_key_exists($name, $this->options)) {
37
            throw new Exception('Invalid option "'.$name.'" for field "'.$this->getName().'"');
38
        }
39
40
        return $this->options[$name];
41
    }
42
43
    public function getTemplate(): string
44
    {
45
        throw new ViewException('The getTemplate() method does not exists for TextView');
46
    }
47
48
    public function getDataTransformer(): ?Closure
49
    {
50
        return $this->dataTransformer;
51
    }
52
}
53