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

KickMessage::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
use Jerodev\PhpIrcClient\IrcClient;
10
11
class KickMessage extends IrcMessage
12
{
13
    public string $message;
14
    public string $kicker;
15
    public string $user;
16
17
    public function __construct(string $message)
18
    {
19
        parent::__construct($message);
20
        [$this->kicker] = explode(' ', $message);
21
        [$this->kicker] = explode('!', $this->kicker);
22
        $this->kicker = substr($this->kicker, 1);
23
24
        [$this->target, $this->user] = explode(' ', $this->commandsuffix ?? '');
25
        $this->message = $this->payload;
26
    }
27
28
    /**
29
     * When the bot is kicked form a channel, it might need to auto-rejoin.
30
     */
31
    public function handle(IrcClient $client, bool $force = false): void
32
    {
33
        if ($this->handled && !$force) {
34
            return;
35
        }
36
37
        if ($client->getNickname() === $this->user && $client->shouldAutoRejoin()) {
38
            $client->join($this->target);
0 ignored issues
show
Bug introduced by
It seems like $this->target can also be of type null; however, parameter $channel of Jerodev\PhpIrcClient\IrcClient::join() 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

38
            $client->join(/** @scrutinizer ignore-type */ $this->target);
Loading history...
39
        }
40
    }
41
42
    /**
43
     * @return array<int, Event>
44
     */
45
    public function getEvents(): array
46
    {
47
        return [
48
            new Event(
49
                'kick',
50
                [$this->channel, $this->user, $this->kicker, $this->message]
51
            ),
52
        ];
53
    }
54
}
55