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

FieldConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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