TextView   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 31.25%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
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
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Field\View;
6
7
use LAG\AdminBundle\Exception\Exception;
8
use LAG\AdminBundle\Exception\Field\ViewException;
9
10
class TextView implements View
11
{
12
    private string $name;
13
    private array $options;
14
    private ?\Closure $dataTransformer;
15
16
    public function __construct(string $name, array $options = [], ?\Closure $dataTransformer = null)
17 1
    {
18
        $this->name = $name;
19 1
        $this->options = $options;
20 1
        $this->dataTransformer = $dataTransformer;
21 1
    }
22 1
23
    public function getName(): string
24
    {
25
        return $this->name;
26
    }
27
28
    public function getOptions(): array
29
    {
30
        return $this->options;
31
    }
32
33
    public function getOption(string $name)
34
    {
35
        if (!\array_key_exists($name, $this->options)) {
36
            throw new Exception('Invalid option "'.$name.'" for field "'.$this->getName().'"');
37
        }
38
39
        return $this->options[$name];
40
    }
41
42
    public function getTemplate(): string
43
    {
44
        throw new ViewException('The getTemplate() method does not exists for TextView');
45
    }
46
47
    public function getDataTransformer(): ?\Closure
48
    {
49
        return $this->dataTransformer;
50
    }
51
}
52