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

FieldView   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 46
ccs 6
cts 18
cp 0.3333
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getOption() 0 7 2
A getOptions() 0 3 1
A getTemplate() 0 3 1
A getDataTransformer() 0 3 1
A getName() 0 3 1
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