SegmentResolver::resolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OneSignal\Resolver;
6
7
use Symfony\Component\OptionsResolver\Options;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
class SegmentResolver implements ResolverInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function resolve(array $data): array
16
    {
17
        return (new OptionsResolver())
18
            ->setDefined('id')
19
            ->setAllowedTypes('id', 'string')
20
            ->setRequired('name')
21
            ->setAllowedTypes('name', 'string')
22
            ->setDefined('filters')
23
            ->setAllowedTypes('filters', 'array')
24
            ->setNormalizer('filters', function (Options $options, array $values) {
25
                return $this->normalizeFilters($options, $values);
26
            })
27
            ->resolve($data);
28
    }
29
30
    private function normalizeFilters(Options $options, array $values): array
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $filters = [];
33
34
        foreach ($values as $filter) {
35
            if (isset($filter['field']) || isset($filter['operator'])) {
36
                $filters[] = $filter;
37
            }
38
        }
39
40
        return $filters;
41
    }
42
}
43