Completed
Push — master ( 56557e...bc0eb2 )
by Julián
02:54
created

Apns::addRecipient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

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.4286
cc 2
eloc 5
nc 2
nop 1
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\Apns as ApnsService;
14
use Jgut\Tify\Recipient\AbstractRecipient;
15
use Jgut\Tify\Recipient\Apns as ApnsRecipient;
16
use Jgut\Tify\Message\AbstractMessage;
17
use Jgut\Tify\Message\Apns as ApnsMessage;
18
19
class Apns extends AbstractNotification
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $defaultOptions = [
25
        'expire' => null,
26
        'badge' => null,
27
        'sound' => null,
28
        'content_available' => null,
29
        'category' => null,
30
    ];
31
32
    /**
33
     * @param \Jgut\Tify\Service\Apns     $service
34
     * @param \Jgut\Tify\Message\Apns     $message
35
     * @param \Jgut\Tify\Recipient\Apns[] $recipients
36
     * @param array                       $options
37
     */
38
    public function __construct(ApnsService $service, ApnsMessage $message, array $recipients = [], array $options = [])
39
    {
40
        parent::__construct($service, $message, $recipients, $options);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @throws \InvalidArgumentException
47
     */
48
    public function setService(AbstractService $service)
49
    {
50
        if (!$service instanceof ApnsService) {
51
            throw new \InvalidArgumentException('Service must be an accepted APNS service');
52
        }
53
54
        $this->service = $service;
55
56
        return $this;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     *
62
     * @throws \InvalidArgumentException
63
     */
64
    public function setMessage(AbstractMessage $message)
65
    {
66
        if (!$message instanceof ApnsMessage) {
67
            throw new \InvalidArgumentException('Message must be an accepted APNS message');
68
        }
69
70
        $this->message = $message;
71
72
        return $this;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     *
78
     * @throws \InvalidArgumentException
79
     */
80
    public function addRecipient(AbstractRecipient $recipient)
81
    {
82
        if (!$recipient instanceof ApnsRecipient) {
83
            throw new \InvalidArgumentException('Recipient must be an accepted APNS recipient');
84
        }
85
86
        $this->recipients[] = $recipient;
87
88
        return $this;
89
    }
90
}
91