GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#58)
by Lukas
04:06 queued 58s
created

OneSignalPayloadFactory   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 76
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B make() 0 24 6
A isTargetingIncludedSegments() 0 4 2
A isTargetingExcludedSegments() 0 4 2
A isTargetingEmail() 0 4 2
A isTargetingTags() 0 4 2
1
<?php
2
3
namespace NotificationChannels\OneSignal;
4
5
use Illuminate\Notifications\Notification;
6
7
class OneSignalPayloadFactory
8
{
9
    /**
10
     * Make a one signal notification payload.
11
     *
12
     * @param mixed $notifiable
13
     * @param \Illuminate\Notifications\Notification $notification
14
     * @param mixed $targeting
15
     *
16
     * @return array
17
     */
18 8
    public static function make($notifiable, Notification $notification, $targeting): array
19
    {
20 8
        $payload = $notification->toOneSignal($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toOneSignal() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
22 8
        if (static::isTargetingEmail($targeting)) {
23 1
            $payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]);
24 7
        } elseif (static::isTargetingTags($targeting)) {
25 2
            $array = $targeting['tags'];
26 2
            $res = count($array) == count($array, COUNT_RECURSIVE);
27 2
            if ($res) {
28 1
                $payload['tags'] = collect([$targeting['tags']]);
29
            } else {
30 2
                $payload['tags'] = collect($targeting['tags']);
31
            }
32 5
        } elseif (static::isTargetingIncludedSegments($targeting)) {
33 1
            $payload['included_segments'] = collect($targeting['included_segments']);
34 4
        } elseif (static::isTargetingExcludedSegments($targeting)) {
35 1
            $payload['excluded_segments'] = collect($targeting['excluded_segments']);
36
        } else {
37 3
            $payload['include_player_ids'] = collect($targeting);
38
        }
39
40 8
        return $payload;
41
    }
42
43
    /**
44
     * @param mixed $targeting
45
     *
46
     * @return bool
47
     */
48 5
    protected static function isTargetingIncludedSegments($targeting)
49
    {
50 5
        return is_array($targeting) && array_key_exists('included_segments', $targeting);
51
    }
52
53
    /**
54
     * @param mixed $targeting
55
     *
56
     * @return bool
57
     */
58 4
    protected static function isTargetingExcludedSegments($targeting)
59
    {
60 4
        return is_array($targeting) && array_key_exists('excluded_segments', $targeting);
61
    }
62
63
    /**
64
     * @param mixed $targeting
65
     *
66
     * @return bool
67
     */
68 8
    protected static function isTargetingEmail($targeting)
69
    {
70 8
        return is_array($targeting) && array_key_exists('email', $targeting);
71
    }
72
73
    /**
74
     * @param mixed $targeting
75
     *
76
     * @return bool
77
     */
78 7
    protected static function isTargetingTags($targeting)
79
    {
80 7
        return is_array($targeting) && array_key_exists('tags', $targeting);
81
    }
82
}
83