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

GcmMessage::setParameter()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 7
nc 2
nop 2
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