Completed
Push — master ( a17349...e5d66a )
by Julián
05:42
created

Gcm::getDefaultOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
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 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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\Notification;
11
12
use Jgut\Tify\Service\AbstractService;
13
use Jgut\Tify\Service\Gcm as GcmService;
14
use Jgut\Tify\Recipient\AbstractRecipient;
15
use Jgut\Tify\Recipient\Gcm as GcmRecipient;
16
use Jgut\Tify\Message\AbstractMessage;
17
use Jgut\Tify\Message\Gcm as GcmMessage;
18
19
class Gcm extends AbstractNotification
20
{
21
    /**
22
     * @param \Jgut\Tify\Service\Gcm     $service
23
     * @param \Jgut\Tify\Message\Gcm     $message
24
     * @param \Jgut\Tify\Recipient\Gcm[] $recipients
25
     * @param array                      $options
26
     */
27
    public function __construct(GcmService $service, GcmMessage $message, array $recipients = [], array $options = [])
28
    {
29
        parent::__construct($service, $message, $recipients, $options);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function getDefaultOptions()
36
    {
37
        return [
38
            'collapse_key' => null,
39
            'delay_while_idle' => null,
40
            'time_to_live' => 2419200,
41
            'restricted_package_name' => null,
42
            'dry_run' => null,
43
        ];
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     *
49
     * @throws \InvalidArgumentException
50
     */
51
    public function setService(AbstractService $service)
52
    {
53
        if (!$service instanceof GcmService) {
54
            throw new \InvalidArgumentException('Service must be an accepted GCM service');
55
        }
56
57
        $this->service = $service;
58
59
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     *
65
     * @throws \InvalidArgumentException
66
     */
67
    public function setMessage(AbstractMessage $message)
68
    {
69
        if (!$message instanceof GcmMessage) {
70
            throw new \InvalidArgumentException('Message must be an accepted GCM message');
71
        }
72
73
        $this->message = $message;
74
75
        return $this;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     *
81
     * @throws \InvalidArgumentException
82
     */
83
    public function addRecipient(AbstractRecipient $recipient)
84
    {
85
        if (!$recipient instanceof GcmRecipient) {
86
            throw new \InvalidArgumentException('Recipient must be an accepted GCM recipient');
87
        }
88
89
        $this->recipients[$recipient->getToken()] = $recipient;
90
91
        return $this;
92
    }
93
}
94