NameReplyMessage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

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