FilterDefaultsTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefaultOptions() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rs\XmlFilter\Filter\Behavior;
6
7
use Rs\XmlFilter\Document\Element;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
trait FilterDefaultsTrait
11
{
12 37
    protected function getDefaultOptions(OptionsResolver $resolver)
13
    {
14
        $defaults = [
15 37
            'sort'      => true,
16
            'condition' => false,
17
            'validate'  => false,
18
            'context'   => null,
19
        ];
20
21 37
        foreach ($defaults as $name => $value) {
22 37
            if (!$resolver->hasDefault($name)) {
23 37
                $resolver->setDefault($name, $value);
24
            }
25
        }
26
27 37
        $resolver->setAllowedTypes('context', ['null', Element::class]);
28 37
        $resolver->setAllowedTypes('sort', ['bool', 'string']);
29 37
        $resolver->setAllowedTypes('condition', ['bool', 'callable']);
30 37
        $resolver->setAllowedTypes('validate', ['bool', 'callable']);
31 37
    }
32
}
33