Passed
Pull Request — master (#12)
by
unknown
08:46
created

PrivmsgMessage::injectChannel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerodev\PhpIrcClient\Messages;
6
7
use Jerodev\PhpIrcClient\Helpers\Event;
8
use Jerodev\PhpIrcClient\IrcChannel;
9
10
class PrivmsgMessage extends IrcMessage
11
{
12
    public string $message;
13
    public string $user;
14
15
    public function __construct(string $message)
16
    {
17
        parent::__construct($message);
18
        $this->user = strstr($this->source ?? '', '!', true);
19
        $this->target = (string)$this->commandsuffix;
20
        $this->message = $this->payload;
21
    }
22
23
    /**
24
     * @return array<int, Event>
25
     */
26
    public function getEvents(): array
27
    {
28
        if ($this->target[0] === '#') {
29
            return [
30
                new Event('message', [$this->user, $this->channel, $this->message]),
31
                new Event("message$this->target", [$this->user, $this->channel, $this->message]),
32
            ];
33
        }
34
        return [
35
            new Event('privmsg', [$this->user, $this->target, $this->message]),
36
        ];
37
    }
38
}
39