Completed
Push — master ( 764ec2...65c5e3 )
by Bence
03:10
created

WrapItPushHelper::sendPush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace WrapIt\Helpers;
4
5
use WrapIt\WrapIt;
6
use WrapIt\Exceptions\WrapItParameterException;
7
use WrapIt\Http\WrapItApiRequester;
8
use WrapIt\Http\WrapItPushRequester;
9
10
/**
11
 * Class WrapItUserHelper
12
 *
13
 * @package WrapIt
14
 */
15
class WrapItPushHelper {
16
17
    private $access_token = null;
18
19
    private $client_id = null;
20
    private $client_secret = null;
21
    private $domain = null;
22
23
    private $requester;
24
25 2
    public function __construct($wi, $access_token = null) {
26 2
        if (!($wi instanceof WrapIt)) {
27
            throw new WrapItParameterException("WrapIt class required");
28
        }
29
30 2
        $this->client_id = $wi->getClientId();
31 2
        $this->client_secret = $wi->getClientSecret();
32 2
        $this->access_token = $access_token;
33 2
        $this->domain = $wi->getDomain();
34 2
        $this->requester = new WrapItPushRequester($this->domain, $this->getAccessToken());
35 2
    }
36
37 2
    private function getAccessToken() {
38 2
        if ($this->access_token != null) {
39 1
            return $this->access_token;
40
        }
41
42 1
        $apirequester = new WrapItApiRequester($this->domain);
43
44 1
        $data = $apirequester->post("access_token", array(
45 1
            "client_id" => $this->client_id,
46 1
            "client_secret" => $this->client_secret,
47
            "grant_type" => "app_token"
48 1
        ));
49
50 1
        if (isset($data["access_token"])) {
51 1
            $this->access_token = $data["access_token"];
52 1
            return $this->access_token;
53
        } else if (isset($data["error"])) {
54
            throw new WrapItParameterException($data["error"]["message"]);
55
        }
56
        throw new WrapItParameterException("Invalid domain or client credentials");
57
    }
58
59
    public function sendPush($userid, $data) {
60
        $data = $this->requester->post("pushservice/$userid", $data);
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
    }
62
63
    public function getPushTemplate() {
64
        return array(
65
            "categories" => array(),
66
            "device_types" => array(
67
                "mail" => false,
68
                "sms" => false,
69
                "browser" => false,
70
                "phone" => false
71
            ),
72
            "properties" => array(
73
                "attribution" => null,
74
                "app_icon" => null,
75
                "hero_image" => null,
76
                "badge" => null,
77
                "sound" => array(
78
                    "UWP" => null,
79
                    "Apple" => null
80
                )
81
            ),
82
            "title" => null,
83
            "lines" => array(),
84
            "actions" => array()
85
        );
86
    }
87
88
}
89