Transport::setUserAgent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Communicator (https://github.com/waltertamboer/communicator)
4
 *
5
 * @link https://github.com/waltertamboer/communicator for the canonical source repository
6
 * @copyright Copyright (c) 2017 Communicator (https://github.com/waltertamboer/communicator)
7
 * @license https://github.com/waltertamboer/communicator/blob/master/LICENSE.md MIT
8
 */
9
10
namespace Communicator\Transport\Webhook;
11
12
use Communicator\Message;
13
use Communicator\Transport\TransportInterface;
14
use Communicator\Transport\Webhook\Adapter\AdapterInterface;
15
16
/**
17
 * A transport that triggers a web hook.
18
 */
19
final class Transport implements TransportInterface
20
{
21
    /**
22
     * The adapter that is used to send the request.
23
     *
24
     * @var AdapterInterface
25
     */
26
    private $adapter;
27
28
    /**
29
     * The url to call.
30
     *
31
     * @var string
32
     */
33
    private $url;
34
35
    /**
36
     * The user agent used to pass along during the request.
37
     *
38
     * @var string
39
     */
40
    private $userAgent;
41
42
    /**
43
     * Initializes a new instance of this class.
44
     *
45
     * @param AdapterInterface $adapter
46
     * @param string $url
47
     */
48
    public function __construct(AdapterInterface $adapter, string $url)
49
    {
50
        $this->adapter = $adapter;
51
        $this->url = $url;
52
        $this->userAgent = 'waltertamboer/communicator';
53
    }
54
55
    /**
56
     * Gets the value of field "url".
57
     *
58
     * @return string
59
     */
60
    public function getUrl(): string
61
    {
62
        return $this->url;
63
    }
64
65
    /**
66
     * Gets the value of field "userAgent".
67
     *
68
     * @return string
69
     */
70
    public function getUserAgent(): string
71
    {
72
        return $this->userAgent;
73
    }
74
75
    /**
76
     * Sets the value of field "userAgent".
77
     *
78
     * @param string $userAgent
79
     */
80
    public function setUserAgent(string $userAgent)
81
    {
82
        $this->userAgent = $userAgent;
83
    }
84
85
    /**
86
     * Sends the message.
87
     *
88
     * @param array $recipients A list with all recipients that should receive the message.
89
     * @param Message $message The message to send.
90
     * @return void
91
     */
92
    public function send(array $recipients, Message $message): void
93
    {
94
        $data = new SendData();
95
        $data->recipients = $recipients;
96
        $data->message = $message;
97
        $data->url = $this->getUrl();
98
        $data->userAgent = $this->getUserAgent();
99
100
        $this->adapter->send($data);
101
    }
102
}
103