Completed
Pull Request — master (#74)
by
unknown
04:19
created

DevicePurchaseResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 22 2
1
<?php
2
3
namespace OneSignal\Resolver;
4
5
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
class DevicePurchaseResolver implements ResolverInterface
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    public function resolve(array $data)
14
    {
15
        $data = (new OptionsResolver())
16
            ->setDefined('existing')
17
            ->setAllowedTypes('existing', 'bool')
18
            ->setRequired('purchases')
19
            ->setAllowedTypes('purchases', 'array')
20
            ->resolve($data);
21
22
        foreach ($data['purchases'] as $key => $purchase) {
23
            $data['purchases'][$key] = (new OptionsResolver())
24
                ->setRequired('sku')
25
                ->setAllowedTypes('sku', 'string')
26
                ->setRequired('amount')
27
                ->setAllowedTypes('amount', 'float')
28
                ->setRequired('iso')
29
                ->setAllowedTypes('iso', 'string')
30
                ->resolve($purchase);
31
        }
32
33
        return $data;
34
    }
35
}