Passed
Pull Request — master (#116)
by Arnaud
05:44 queued 02:35
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\OptionsResolver;
7
8
class FieldConfiguration extends Configuration
9
{
10
    /**
11
     * @var array
12
     */
13
    private $allowedFields;
14
15
    public function __construct(array $allowedFields = [])
16
    {
17
        $this->allowedFields = $allowedFields;
18
19
        parent::__construct();
20
    }
21
22
    public function configureOptions(OptionsResolver $resolver): void
23
    {
24
        $resolver
25
            ->setDefaults([
26
                'type' => null,
27
                'options' => [],
28
            ])
29
            // Set allowed fields type from tagged services
30
            ->setAllowedValues('type', array_merge([null], $this->allowedFields))
31
            ->setAllowedTypes('type', [
32
                'string',
33
                'null',
34
            ])
35
            ->setAllowedTypes('options', 'array')
36
        ;
37
    }
38
39
    public function getType(): ?string
40
    {
41
        return $this->get('type');
42
    }
43
44
    public function getOptions(): array
45
    {
46
        return $this->get('options');
47
    }
48
}
49