Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/ApnChannel.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SemyonChetvertnyh\ApnNotificationChannel;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Notifications\Notification;
7
use Pushok\Client;
8
use Pushok\Notification as PushokNotification;
9
use Pushok\Payload;
10
use Pushok\Payload\Alert;
11
use SemyonChetvertnyh\ApnNotificationChannel\Exceptions\CouldNotSendNotification;
12
use SemyonChetvertnyh\ApnNotificationChannel\Exceptions\InvalidPayloadException;
13
14
class ApnChannel
15
{
16
    /**
17
     * The Pushok Client instance.
18
     *
19
     * @var \Pushok\Client
20
     */
21
    protected $client;
22
23
    /**
24
     * Create an instance of APN channel.
25
     *
26
     * @param  \Pushok\Client  $client
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct(Client $client)
30
    {
31
        $this->client = $client;
32
    }
33
34
    /**
35
     * Send the given notification.
36
     *
37
     * @param  mixed  $notifiable
38
     * @param  \Illuminate\Notifications\Notification  $notification
39
     * @return void
40
     *
41
     * @throws \SemyonChetvertnyh\ApnNotificationChannel\Exceptions\InvalidPayloadException
42
     * @throws \SemyonChetvertnyh\ApnNotificationChannel\Exceptions\CouldNotSendNotification
43
     */
44
    public function send($notifiable, Notification $notification)
45
    {
46
        if (! $deviceTokens = $notifiable->routeNotificationFor('apn', $notification)) {
47
            return;
48
        }
49
50
        $this->client->addNotifications(
51
            $this->notifications($notification->toApn($notifiable), $deviceTokens)
0 ignored issues
show
The method toApn() 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...
52
        );
53
54
        $responses = $this->client->push();
55
56
        ApnsResponseCollection::make($responses)
57
            ->onlyUnsuccessful()
58
            ->unlessEmpty(function (ApnsResponseCollection $responses) {
59
                throw CouldNotSendNotification::withUnsuccessful($responses);
60
            });
61
    }
62
63
    /**
64
     * Format an array with notifications.
65
     *
66
     * @param  \SemyonChetvertnyh\ApnNotificationChannel\ApnMessage  $message
67
     * @param  \Illuminate\Contracts\Support\Arrayable|array  $deviceTokens
68
     * @return \Pushok\Notification[]
69
     */
70
    protected function notifications(ApnMessage $message, $deviceTokens)
71
    {
72
        $deviceTokens = $deviceTokens instanceof Arrayable ? $deviceTokens->toArray() : $deviceTokens;
73
74
        return collect($deviceTokens)->map(function ($deviceToken) use ($message) {
75
            return new PushokNotification($this->payload($message), $deviceToken);
76
        })->all();
77
    }
78
79
    /**
80
     * Format a payload.
81
     *
82
     * @param  \SemyonChetvertnyh\ApnNotificationChannel\ApnMessage  $message
83
     * @return \Pushok\Payload
84
     *
85
     * @throws \SemyonChetvertnyh\ApnNotificationChannel\Exceptions\InvalidPayloadException
86
     */
87
    protected function payload(ApnMessage $message)
88
    {
89
        $payload = Payload::create()
90
            ->setAlert($this->alert($message));
91
92
        if ($isContentAvailable = $message->isContentAvailable()) {
93
            $payload->setContentAvailability($isContentAvailable);
94
        }
95
96
        if ($hasMutableContent = $message->hasMutableContent()) {
97
            $payload->setMutableContent($hasMutableContent);
98
        }
99
100
        if (! is_null($message->badge)) {
101
            $payload->setBadge($message->badge);
102
        }
103
104
        if (! is_null($message->sound)) {
105
            $payload->setSound($message->sound);
106
        }
107
108
        if (! is_null($message->category)) {
109
            $payload->setCategory($message->category);
110
        }
111
112
        if (! is_null($message->threadId)) {
113
            $payload->setThreadId($message->threadId);
114
        }
115
116
        try {
117
            foreach ($message->custom as $key => $value) {
118
                $payload->setCustomValue($key, $value);
119
            }
120
        } catch (\Exception $e) {
121
            throw new InvalidPayloadException($e->getMessage());
122
        }
123
124
        return $payload;
125
    }
126
127
    /**
128
     * Format an alert.
129
     *
130
     * @param  \SemyonChetvertnyh\ApnNotificationChannel\ApnMessage  $message
131
     * @return \Pushok\Payload\Alert
132
     */
133
    protected function alert(ApnMessage $message)
134
    {
135
        $alert = Alert::create();
136
137
        if ($message->title) {
138
            $alert->setTitle($message->title);
139
        }
140
141
        if ($message->subtitle) {
142
            $alert->setSubtitle($message->subtitle);
143
        }
144
145
        if ($message->body) {
146
            $alert->setBody($message->body);
147
        }
148
149
        if ($message->launchImage) {
150
            $alert->setLaunchImage($message->launchImage);
151
        }
152
153
        if ($message->titleLocArgs) {
154
            $alert->setTitleLocArgs($message->titleLocArgs);
155
        }
156
157
        if (! is_null($message->titleLocKey)) {
158
            $alert->setTitleLocKey($message->titleLocKey);
159
        }
160
161
        if (! is_null($message->actionLocKey)) {
162
            $alert->setActionLocKey($message->actionLocKey);
163
        }
164
165
        if (! empty($message->locArgs)) {
166
            $alert->setLocArgs($message->locArgs);
167
        }
168
169
        if ($message->locKey) {
170
            $alert->setLocKey($message->locKey);
171
        }
172
173
        return $alert;
174
    }
175
}
176