Completed
Push — master ( b93c78...0ed572 )
by Julián
02:22
created

GcmMessage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A setParameter() 0 14 3
1
<?php
2
/**
3
 * Push notification services abstraction (http://github.com/juliangut/tify)
4
 *
5
 * @link https://github.com/juliangut/tify for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Tify\Message;
11
12
class GcmMessage extends AbstractMessage
13
{
14
    /**
15
     * List of Google service's reserved parameters.
16
     *
17
     * @var array
18
     */
19
    protected static $reservedParameters = [
20
        'from',
21
        'collapse_key',
22
        'delay_while_idle',
23
        'time_to_live',
24
        'restricted_package_name',
25
        'dry_run',
26
    ];
27
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @throws \InvalidArgumentException
32
     */
33
    public function setParameter($parameter, $value)
34
    {
35
        $parameter = trim($parameter);
36
37
        if (preg_match('/^(google|gcm)/', $parameter) || in_array($parameter, self::$reservedParameters)) {
38
            throw new \InvalidArgumentException(
39
                sprintf('"%s" can not be used as a custom parameter as it is reserved', $parameter)
40
            );
41
        }
42
43
        $this->parameters[$parameter] = $value;
44
45
        return $value;
46
    }
47
}
48