Completed
Push — master ( 869412...764ec2 )
by Bence
02:01
created

WrapItPushHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 46.34%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 4
dl 0
loc 72
ccs 19
cts 41
cp 0.4634
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A sendPush() 0 3 1
B getPushTemplate() 0 24 1
A getAccessToken() 0 19 3
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
        }
54
        throw new WrapItParameterException("Invalid domain or client credentials");
55
    }
56
57
    public function sendPush($userid, $data) {
58
        $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...
59
    }
60
61
    public function getPushTemplate() {
62
        return array(
63
            "categories" => array(),
64
            "device_types" => array(
65
                "mail" => false,
66
                "sms" => false,
67
                "browser" => false,
68
                "phone" => false
69
            ),
70
            "properties" => array(
71
                "attribution" => null,
72
                "app_icon" => null,
73
                "hero_image" => null,
74
                "badge" => null,
75
                "sound" => array(
76
                    "UWP" => null,
77
                    "Apple" => null
78
                )
79
            ),
80
            "title" => null,
81
            "lines" => array(),
82
            "actions" => array()
83
        );
84
    }
85
86
}
87