Completed
Pull Request — master (#116)
by Arnaud
08:19
created

FieldConfiguration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOptions() 0 3 1
A configureOptions() 0 14 1
A getType() 0 3 1
1
<?php
2
3
namespace LAG\AdminBundle\Configuration;
4
5
use JK\Configuration\Configuration;
6
use Symfony\Component\OptionsResolver\Options;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
class FieldConfiguration extends Configuration
10
{
11
    /**
12
     * @var array
13
     */
14
    private $allowedFields;
15
16
    public function __construct(array $allowedFields = [])
17
    {
18
        $this->allowedFields = $allowedFields;
19
20
        parent::__construct();
21
    }
22
23
    public function configureOptions(OptionsResolver $resolver): void
24
    {
25
        $resolver
26
            ->setDefaults([
27
                'type' => null,
28
                'options' => [],
29
            ])
30
            // Set allowed fields type from tagged services
31
            ->setAllowedValues('type', array_merge([null], $this->allowedFields))
32
            ->setAllowedTypes('type', [
33
                'string',
34
                'null',
35
            ])
36
            ->setAllowedTypes('options', 'array')
37
        ;
38
    }
39
40
    public function getType(): ?string
41
    {
42
        return $this->get('type');
43
    }
44
45
    public function getOptions(): array
46
    {
47
        return $this->get('options');
48
    }
49
}
50