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

FieldView::getOptions()   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
10
class FieldView implements View
11
{
12
    private string $fieldName;
13
    private string $template;
14
    private array $options;
15
    private ?Closure $dataTransformer;
16
17 2
    public function __construct(
18
        string $fieldName,
19
        string $template,
20
        array $options = [],
21
        ?Closure $dataTransformer = null
22
    ) {
23 2
        $this->fieldName = $fieldName;
24 2
        $this->template = $template;
25 2
        $this->options = $options;
26 2
        $this->dataTransformer = $dataTransformer;
27 2
    }
28
29
    public function getName(): string
30
    {
31
        return $this->fieldName;
32
    }
33
34
    public function getOptions(): array
35
    {
36
        return $this->options;
37
    }
38
39
    public function getOption(string $name)
40
    {
41
        if (!\array_key_exists($name, $this->options)) {
42
            throw new Exception('Invalid option "'.$name.'" for field "'.$this->getName().'"');
43
        }
44
45
        return $this->options[$name];
46
    }
47
48
    public function getTemplate(): string
49
    {
50
        return $this->template;
51
    }
52
53
    public function getDataTransformer(): ?Closure
54
    {
55
        return $this->dataTransformer;
56
    }
57
}
58