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

ModeMessage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 2
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getEvents() 0 4 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
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