Completed
Push — development ( 043bde...8d8ba4 )
by Sebastian
13s
created

classes/push_notification/notifymyandroid.php (1 issue)

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
class Notifications_NotifyMyAndroid implements IPushNotification {
3
    
4
    private $apiKey;
5
    public function __construct($apikey){
6
        $this->apiKey = $apikey;
7
    }
8
    
9
    static $priorities = array(
10
        0 => 'info',
11
        2 => 'error',
12
    );
13
    
14
    public static function getName(){
15
        return  "notifymyandroid.com";
16
    }
17
    
18
    public static function getParameters(){
19
        return array(
20
            'apikey' => 'API key',
21
        );
22
    }
23
    
24
    public function notify($message, $severity = 'info', $event = null){
25
        global $setting;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
26
        curl_setopt_array($ch = curl_init(), array(
27
            CURLOPT_URL => "https://www.notifymyandroid.com/publicapi/notify",
28
            CURLOPT_POST => true,
29
            CURLOPT_RETURNTRANSFER => true,
30
            CURLOPT_POSTFIELDS => http_build_query($data = array(
31
                "apikey" => $this->apiKey,
32
                "application" => $setting->getValue('website_title')?:"PHP-MPOS",
33
                "description" => $message,
34
                "content-type" => "text/html",
35
                "event" => $event,
36
                "priority" => array_search($severity, self::$priorities),
37
            )),
38
        ));
39
        curl_exec($ch);
40
        curl_close($ch);
41
    }
42
}