Message   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 74
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
getPayload() 0 1 ?
A getPayloadAsJson() 0 4 1
A getTokens() 0 4 1
A setTokens() 0 6 1
A addToken() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the MobileNotif package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace LinkValue\MobileNotif\Model;
11
12
/**
13
 * Message
14
 * Definition of message for push notification.
15
 *
16
 * @author  Jamal Youssefi <[email protected]>
17
 * @author  Valentin Coulon <[email protected]>
18
 */
19
abstract class Message
20
{
21
    /**
22
     * The devices token.
23
     *
24
     * @var array
25
     */
26
    protected $tokens;
27
28
    /**
29
     * Constructor.
30
     */
31 106
    public function __construct()
32
    {
33 106
        $this->tokens = array();
34 106
    }
35
36
    /**
37
     * Get the Payload message to push
38
     *
39
     * @return array
40
     */
41
    abstract public function getPayload();
42
43
    /**
44
     * Get the Payload message to push converted in json 
45
     *
46
     * @return string json payload message
47
     */
48 4
    public function getPayloadAsJson()
49
    {
50 4
        return json_encode($this->getPayload());
51
    }
52
53
    /**
54
     * Get the list token devices.
55
     *
56
     * @return array
57
     */
58 10
    public function getTokens()
59
    {
60 10
        return $this->tokens;
61
    }
62
63
    /**
64
     * Set the list of token devices.
65
     *
66
     * @param array $tokens
67
     *
68
     * @return self
69
     */
70 4
    public function setTokens(array $tokens)
71
    {
72 4
        $this->tokens = array_unique($tokens);
73
74 4
        return $this;
75
    }
76
77
    /**
78
     * Add a token device.
79
     *
80
     * @param string $token
81
     *
82
     * @return self
83
     */
84 10
    public function addToken($token)
85
    {
86 10
        if (!in_array($token, $this->tokens)) {
87 10
            $this->tokens[] = $token;
88 10
        }
89
90 10
        return $this;
91
    }
92
}
93