Passed
Branch master (c73d10)
by Stefan
02:51 queued 55s
created

sendWelcome()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 16
rs 10
c 1
b 0
f 1
1
<?php
2
require_once 'MyVapid.php';
3
4
use SKien\PNServer\PNServer;
5
use SKien\PNServer\PNSubscription;
6
use SKien\PNServer\PNPayload;
7
8
/**
9
 * Example to demonstarte how to send a welcome notification to each 
10
 * user newly subscribed our service.
11
 * 
12
 * This function is called within the Handler for the HTTP-Request send from
13
 * the ServiceWorker to subscribe. (PNSubscriber.php)
14
 * After the subscription was saved in the database, this function is called,
15
 * if the var $bSendWelcome is set to true!
16
 * 
17
 * THIS CODE IS INTENDED ONLY AS EXAMPLE - DONT USE IT DIRECT IN YOU PROJECT  
18
 * 
19
 * @author Stefanius <[email protected]>
20
 * @copyright MIT License - see the LICENSE file for details
21
 */
22
23
/**
24
 * @param PNSubscription $oSubscription
25
 */
26
function sendWelcome(PNSubscription $oSubscription)
27
{
28
    // create server. Since we are sending to a single subscription that was 
29
    // passed as argument, we do not need a dataprovider
30
    $oServer = new PNServer();
31
    
32
    // create payload message for welcome...
33
    $oPayload = new PNPayload('Welcome to PNServer', 'We warmly welcome you to our homepage.', './elephpant.png');
34
    
35
    // set VAPID, payload and the passed subscription
36
    $oServer->setVapid(getMyVapid());
0 ignored issues
show
Bug introduced by
The function getMyVapid was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
    $oServer->setVapid(/** @scrutinizer ignore-call */ getMyVapid());
Loading history...
37
    $oServer->setPayload($oPayload);
38
    $oServer->addSubscription($oSubscription);
39
    
40
    // ... and finally push the notification!
41
    $oServer->push();
42
}