Issues (8)

src/resolver/DeviceResolver.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace vasadibt\onesignal\resolver;
4
5
use OneSignal\Devices;
0 ignored issues
show
The type OneSignal\Devices was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
use vasadibt\onesignal\OneSignal;
8
use yii\base\BaseObject;
0 ignored issues
show
The type yii\base\BaseObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Class DeviceResolver
12
 * @package vasadibt\onesignal\resolver
13
 */
14
class DeviceResolver extends BaseObject implements ResolverInterface
15
{
16
    /**
17
     * @var bool
18
     */
19
    public $isNewDevice;
20
    /**
21
     * @var OneSignal
22
     */
23
    public $api;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function resolve(array $data)
29
    {
30
        /** @var OptionsResolver $resolver */
31
        $resolver = (new OptionsResolver())
32
            ->setDefined('identifier')
33
            ->setAllowedTypes('identifier', 'string')
34
            ->setDefined('language')
35
            ->setAllowedTypes('language', 'string')
36
            ->setDefined('timezone')
37
            ->setAllowedTypes('timezone', 'int')
38
            ->setDefined('game_version')
39
            ->setAllowedTypes('game_version', 'string')
40
            ->setDefined('device_model')
41
            ->setAllowedTypes('device_model', 'string')
42
            ->setDefined('device_os')
43
            ->setAllowedTypes('device_os', 'string')
44
            ->setDefined('ad_id')
45
            ->setAllowedTypes('ad_id', 'string')
46
            ->setDefined('sdk')
47
            ->setAllowedTypes('sdk', 'string')
48
            ->setDefined('session_count')
49
            ->setAllowedTypes('session_count', 'int')
50
            ->setDefined('tags')
51
            ->setAllowedTypes('tags', 'array')
52
            ->setDefined('amount_spent')
53
            ->setAllowedTypes('amount_spent', 'float')
54
            ->setDefined('created_at')
55
            ->setAllowedTypes('created_at', 'int')
56
            ->setDefined('playtime')
57
            ->setAllowedTypes('playtime', 'int')
58
            ->setDefined('badge_count')
59
            ->setAllowedTypes('badge_count', 'int')
60
            ->setDefined('last_active')
61
            ->setAllowedTypes('last_active', 'int')
62
            ->setDefined('notification_types')
63
            ->setAllowedTypes('notification_types', 'int')
64
            ->setAllowedValues('notification_types', [1, -2])
65
            ->setDefined('test_type')
66
            ->setAllowedTypes('test_type', 'int')
67
            ->setAllowedValues('test_type', [1, 2])
68
            ->setDefined('long')
69
            ->setAllowedTypes('long', 'double')
70
            ->setDefined('lat')
71
            ->setAllowedTypes('lat', 'double')
72
            ->setDefined('country')
73
            ->setAllowedTypes('country', 'string')
74
            ->setDefault('app_id', $this->api->appId)
75
            ->setAllowedTypes('app_id', 'string');
76
77
        if ($this->isNewDevice) {
78
            $resolver
79
                ->setRequired('device_type')
80
                ->setAllowedTypes('device_type', 'int')
81
                ->setAllowedValues('device_type', [
82
                    Devices::IOS,
83
                    Devices::ANDROID,
84
                    Devices::AMAZON,
85
                    Devices::WINDOWS_PHONE,
86
                    Devices::WINDOWS_PHONE_MPNS,
87
                    Devices::CHROME_APP,
88
                    Devices::CHROME_WEB,
89
                    Devices::WINDOWS_PHONE_WNS,
90
                    Devices::SAFARI,
91
                    Devices::FIREFOX,
92
                    Devices::MACOS,
93
                    Devices::ALEXA,
94
                    Devices::EMAIL,
95
                ]);
96
        }
97
98
        return $resolver->resolve($data);
99
    }
100
}
101