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

TextView   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 29.4%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 1
b 0
f 0
dl 0
loc 40
ccs 5
cts 17
cp 0.294
rs 10

6 Methods

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