Message::getChannel()   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 0
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;
11
12
/**
13
 * A message that can be sent over a transport.
14
 */
15
final class Message
16
{
17
    /**
18
     * @var string
19
     */
20
    private $channel;
21
22
    /**
23
     * @var array
24
     */
25
    private $params;
26
27
    /**
28
     * @var array
29
     */
30
    private $options;
31
32
    /**
33
     * Initializes a new instance of this class.
34
     *
35
     * @param string $channel The name of the channel to broadcast the message to.
36
     * @param array $params The parameters that belong to the message.
37
     * @param array $options Options that can be passed along to the transport.
38
     */
39
    public function __construct(string $channel, array $params, array $options)
40
    {
41
        $this->channel = $channel;
42
        $this->params = $params;
43
        $this->options = $options;
44
45
        if (!array_key_exists('locale', $this->options)) {
46
            $this->options['locale'] = class_exists('Locale') ? \Locale::getDefault() : 'en-US';
47
        }
48
    }
49
50
    /**
51
     * Gets the value of field "channel".
52
     *
53
     * @return string
54
     */
55
    public function getChannel(): string
56
    {
57
        return $this->channel;
58
    }
59
60
    /**
61
     * Gets the value of field "params".
62
     *
63
     * @return array
64
     */
65
    public function getParams(): array
66
    {
67
        return $this->params;
68
    }
69
70
    /**
71
     * Gets the parameter with the given name.
72
     *
73
     * @param string $name
74
     * @param mixed $default
75
     * @return mixed
76
     */
77
    public function getParam(string $name, $default = null)
78
    {
79
        if (array_key_exists($name, $this->params)) {
80
            return $this->params[$name];
81
        }
82
83
        return $default;
84
    }
85
86
    /**
87
     * Gets the value of field "options".
88
     *
89
     * @return array
90
     */
91
    public function getOptions(): array
92
    {
93
        return $this->options;
94
    }
95
96
    /**
97
     * Gets the option with the given name.
98
     *
99
     * @param string $name
100
     * @param mixed $default
101
     * @return mixed
102
     */
103
    public function getOption(string $name, $default = null)
104
    {
105
        if (array_key_exists($name, $this->options)) {
106
            return $this->options[$name];
107
        }
108
109
        return $default;
110
    }
111
}
112