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

ModeMessage::getEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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
use Jerodev\PhpIrcClient\IrcClient;
10
11
class ModeMessage extends IrcMessage
12
{
13
    public string $mode;
14
    public ?string $target = null;
15
    public string $user;
16
17
    public function __construct(string $command)
18
    {
19
        parent::__construct($command);
20
        if ('#' === $this->commandsuffix[0]) {
21
            [$this->target, $this->mode] = explode(' ', $this->commandsuffix);
0 ignored issues
show
Bug introduced by
It seems like $this->commandsuffix can also be of type null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
            [$this->target, $this->mode] = explode(' ', /** @scrutinizer ignore-type */ $this->commandsuffix);
Loading history...
22
            $this->user = $this->payload;
23
            $this->channel = new IrcChannel($this->target);
24
        } else {
25
            $this->user = $this->commandsuffix;
26
            $this->mode = $this->payload;
27
        }
28
    }
29
30
    /**
31
     * @return array<int, Event>
32
     */
33
    public function getEvents(): array
34
    {
35
        return [
36
            new Event('mode', [$this->channel, $this->user, $this->mode]),
37
        ];
38
    }
39
}
40