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/PushNotification.php (3 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
namespace nstdio\notymo;
3
use Closure;
4
5
/**
6
 * Class PushNotificationComponent
7
 */
8
class PushNotification implements PushNotificationInterface, LifeCycleCallback
9
{
10
    /**
11
     * @var PushNotificationInterface[]
12
     */
13
    private $notificationImpl = array();
14
15
    /**
16
     * PushNotification constructor.
17
     *
18
     * @param array $config Configuration for notification implementations.
19
     *
20
     * Available keys.
21
     * - skipApns Whether use APNS notifications.
22
     * - skipGcm  Whether use GCM notifications
23
     * - apns
24
     *      - live
25
     *      - cert
26
     *      - sandboxCert
27
     * - gcm
28
     *      - apiKey Google Api key for GCM service.
29
     */
30 3
    public function __construct($config = array())
31
    {
32 3
        $this->notificationImpl = array();
33
34 3
        $this->initApns($config);
35 2
        $this->initGcm($config);
36 1
    }
37
38
    /**
39
     * @param $config
40
     */
41 3
    private function initApns($config)
42
    {
43 3
        if (!isset($config['skipApns'])) {
44 2
            if (!isset($config['apns'])) {
45 1
                throw new \InvalidArgumentException("Configuration required for APNSNotification.");
46
            }
47
48 1
            $args = array_merge(array('live' => false, 'cert' => null, 'sandboxCert' => null), $config['apns']);
49 1
            $this->notificationImpl['apns'] = new APNSNotification($args['live'], $args['cert'], $args['sandboxCert']);
0 ignored issues
show
It seems like $args['live'] can also be of type null; however, nstdio\notymo\APNSNotification::__construct() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $args['cert'] can also be of type false; however, nstdio\notymo\APNSNotification::__construct() does only seem to accept string|null, did you maybe forget to handle an error condition?
Loading history...
It seems like $args['sandboxCert'] can also be of type false; however, nstdio\notymo\APNSNotification::__construct() does only seem to accept string|null, did you maybe forget to handle an error condition?
Loading history...
50 1
        }
51 2
    }
52
53
    /**
54
     * @param $config
55
     */
56 2
    private function initGcm($config)
57
    {
58 2
        if (!isset($config['skipGcm'])) {
59 2
            if (!isset($config['gcm']) || !isset($config['gcm']['apiKey'])) {
60 1
                throw new \InvalidArgumentException("Configuration required for GCMNotification.");
61
            }
62 1
            $this->notificationImpl['gcm'] = new GCMNotification($config['gcm']['apiKey']);
63 1
        }
64 1
    }
65
66
    /**
67
     *
68
     */
69
    public function send()
70
    {
71
        $this->invokeMethod('send');
72
    }
73
74
    private function invokeMethod($method, $args = array())
75
    {
76
        foreach ($this->notificationImpl as $item) {
77
            call_user_func_array(array($item, $method), $args);
78
        }
79
    }
80
81
    public function enqueue(MessageInterface $message)
82
    {
83
        if ($message->getType() === MessageInterface::TYPE_IOS && isset($this->notificationImpl['apns'])) {
84
            $this->notificationImpl['apns']->enqueue($message);
85
        } elseif ($message->getType() === MessageInterface::TYPE_ANDROID && isset($this->notificationImpl['gcm'])) {
86
            $this->notificationImpl['gcm']->enqueue($message);
87
        }
88
    }
89
90
    public function setStreamWrapper(Connection $wrapper)
91
    {
92
        throw new \RuntimeException('Not yet implemented.');
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function onComplete(\Closure $param)
99
    {
100
        $this->invokeMethod('onSent', array($param));
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function onEachSent(\Closure $callback)
107
    {
108
        $this->invokeMethod('onEachSent', array($callback));
109
    }
110
111
    /**
112
     * Removes all callbacks.
113
     */
114
    public function detach()
115
    {
116
        $this->invokeMethod('detach');
117
    }
118
119
    /**
120
     * @param int $count
121
     */
122
    public function setRetryCount($count)
123
    {
124
        $this->invokeMethod('setRetryCount', array($count));
125
    }
126
127
    /**
128
     * @inheritdoc
129
     */
130
    public function onError(Closure $callback)
131
    {
132
        $this->invokeMethod('onError', array($callback));
133
    }
134
}
135