Client::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace JWage\APNS;
4
5
class Client
6
{
7
    /**
8
     * @var \JWage\APNS\SocketClient
9
     */
10
    private $socketClient;
11
12
    /**
13
     * Construct.
14
     *
15
     * @param \JWage\APNS\SocketClient $socketClient
16
     */
17
    public function __construct(SocketClient $socketClient)
18
    {
19
        $this->socketClient = $socketClient;
20
    }
21
22
    /**
23
     * Send Payload instance to a given device token.
24
     *
25
     * @param string $deviceToken The device token to send payload to.
26
     * @param \JWage\APNS\Payload $payload The payload to send to device token.
27
     */
28
    public function sendPayload($deviceToken, Payload $payload)
29
    {
30
        return $this->socketClient->write(
31
            $this->createApnMessage($deviceToken, $payload)->getBinaryMessage()
32
        );
33
    }
34
35
    /**
36
     * Creates an APNSMessage instance for the given device token and payload.
37
     *
38
     * @param string $deviceToken
39
     * @param \JWage\APNS\Payload $payload
40
     * @return \JWage\APNS\APNSMessage
41
     */
42
    protected function createApnMessage($deviceToken, Payload $payload)
43
    {
44
        return new APNSMessage($deviceToken, $payload);
45
    }
46
}
47