Total Complexity | 9 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class IrcChannel |
||
8 | { |
||
9 | /** @var string */ |
||
10 | private $name; |
||
11 | |||
12 | /** @var null|string */ |
||
13 | private $topic; |
||
14 | |||
15 | /** @var string[] */ |
||
16 | private $users; |
||
17 | |||
18 | public function __construct(string $name) |
||
19 | { |
||
20 | $name = trim($name); |
||
21 | if (empty($name)) { |
||
22 | throw new Exception('Channel name is empty.'); |
||
23 | } |
||
24 | |||
25 | if ($name[0] !== '#') { |
||
26 | $name = "#$name"; |
||
27 | } |
||
28 | $this->name = $name; |
||
29 | $this->users = []; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Fetch the name of the channel, including the `#`. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getName(): string |
||
38 | { |
||
39 | return $this->name; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Get the current channel topic. |
||
44 | * |
||
45 | * @return null|string |
||
46 | */ |
||
47 | public function getTopic() |
||
48 | { |
||
49 | return $this->topic; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Fetch the list of users currently on this channel. |
||
54 | * |
||
55 | * @return string[] |
||
56 | */ |
||
57 | public function getUsers(): array |
||
58 | { |
||
59 | return $this->users; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Set the current channel topic. |
||
64 | * |
||
65 | * @param string $topic The topic |
||
66 | */ |
||
67 | public function setTopic(string $topic): void |
||
68 | { |
||
69 | $this->topic = $topic; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Set the list of active users on the channel. |
||
74 | * User modes (`+`, `@`) will be removed from the nicknames. |
||
75 | * |
||
76 | * @param string[] $users An array of user names. |
||
77 | */ |
||
78 | public function setUsers(array $users): void |
||
87 | } |
||
88 | } |
||
89 |