FieldView::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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