Completed
Push — develop ( 548ee0...0abce4 )
by Romain
02:09
created

GcmComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 9
Bugs 3 Features 3
Metric Value
wmc 5
c 9
b 3
f 3
lcom 1
cbo 2
dl 0
loc 71
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 4 1
A sendNotification() 0 4 1
A sendData() 0 4 1
A response() 0 4 1
1
<?php
2
namespace ker0x\CakeGcm\Controller\Component;
3
4
use Cake\Controller\Component;
5
use Cake\Controller\ComponentRegistry;
6
use ker0x\CakeGcm\Lib\Gcm;
7
use \Exception;
8
9
/**
10
 * Gcm Component
11
 *
12
 */
13
class GcmComponent extends Component
14
{
15
16
    /**
17
     * Response of the request
18
     *
19
     * @var object
20
     */
21
    protected $_gcm = null;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param ComponentRegistry $registry A ComponentRegistry
27
     * @param array $config Array of configuration settings
28
     */
29
    public function __construct(ComponentRegistry $registry, array $config = [])
30
    {
31
        $this->_gcm = new Gcm($config);
32
    }
33
34
    /**
35
     * Send a downstream message to one or more devices
36
     *
37
     * @param mixed $ids Devices'ids
38
     * @param array $payload The notification and/or some datas
39
     * @param array $parameters Parameters for the GCM request
40
     * @throws Exception
41
     * @return bool
42
     */
43
    public function send($ids = null, array $payload = [], array $parameters = [])
44
    {
45
        return $this->_gcm->send($ids, $payload, $parameters);
46
    }
47
48
    /**
49
     * Shortcut to send notification
50
     *
51
     * @param mixed $ids Devices'ids
52
     * @param array $notification The notification
53
     * @param array $parameters Parameters for the GCM request
54
     * @return bool
55
     */
56
    public function sendNotification($ids = null, array $notification = [], array $parameters = [])
57
    {
58
        return $this->_gcm->sendNotification($ids, $notification, $parameters);
59
    }
60
61
    /**
62
     * Shortcut to send datas
63
     *
64
     * @param mixed $ids Devices'ids
65
     * @param array $data Some datas
66
     * @param array $parameters Parameters for the GCM request
67
     * @return bool
68
     */
69
    public function sendData($ids = null, array $data = [], array $parameters = [])
70
    {
71
        return $this->_gcm->sendData($ids, $data, $parameters);
72
    }
73
74
    /**
75
     * Return the response of the push
76
     *
77
     * @return string
78
     */
79
    public function response()
80
    {
81
        return $this->_gcm->response();
82
    }
83
}
84