Completed
Push — master ( 7c39f2...831177 )
by Jeroen
04:12
created

TopicChangeMessage::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
use Jerodev\PhpIrcClient\IrcClient;
6
7
class TopicChangeMessage extends IrcMessage
8
{
9
    /** @var string */
10
    public $channel;
11
12
    /** @var string */
13
    public $topic;
14
15
    public function __construct(string $message)
16
    {
17
        parent::__construct($message);
18
19
        $this->channel = preg_replace('/^[^\#]*(\#.*?)$/', '$1', $this->commandsuffix);
20
        $this->topic = $this->payload;
21
    }
22
    
23
    /**
24
     *  Change the topic for the referenced channel
25
     */
26
    public function handle(IrcClient $client, bool $force = false): void
27
    {
28
        if ($this->handled && !$force) {
29
            return;
30
        }
31
        
32
        $client->getChannel($this->channel)->setTopic($this->topic);
33
    }
34
}
35