TopicChangeMessage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 7 3
A getEvents() 0 4 1
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
use Jerodev\PhpIrcClient\Helpers\Event;
6
use Jerodev\PhpIrcClient\IrcClient;
7
8
class TopicChangeMessage extends IrcMessage
9
{
10
    /** @var string */
11
    public $channel;
12
13
    /** @var string */
14
    public $topic;
15
16
    /** @var string */
17
    public $user;
18
19
    public function __construct(string $message)
20
    {
21
        parent::__construct($message);
22
23
        $this->channel = strstr($this->commandsuffix, '#');
24
        $this->topic = $this->payload;
25
    }
26
27
    /**
28
     *  Change the topic for the referenced channel.
29
     */
30
    public function handle(IrcClient $client, bool $force = false): void
31
    {
32
        if ($this->handled && !$force) {
33
            return;
34
        }
35
36
        $client->getChannel($this->channel)->setTopic($this->topic);
37
    }
38
39
    public function getEvents(): array
40
    {
41
        return [
42
            new Event('topic', [$this->channel, $this->topic]),
43
        ];
44
    }
45
}
46