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

TopicChangeMessage::getEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 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 TopicChangeMessage extends IrcMessage
12
{
13
    public string $topic;
14
15
    public function __construct(string $message)
16
    {
17
        parent::__construct($message);
18
        $this->channel = new IrcChannel(strstr($this->commandsuffix ?? '', '#'));
19
        $this->topic = $this->payload;
20
    }
21
22
    /**
23
     * Change the topic for the referenced channel.
24
     */
25
    public function handle(IrcClient $client, bool $force = false): void
26
    {
27
        if ($this->handled && !$force) {
28
            return;
29
        }
30
31
        $client->getChannel($this->channel->getName())->setTopic($this->topic);
0 ignored issues
show
Bug introduced by
The method getName() does not exist on null. ( Ignorable by Annotation )

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

31
        $client->getChannel($this->channel->/** @scrutinizer ignore-call */ getName())->setTopic($this->topic);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
    }
33
34
    /**
35
     * @return array<int, Event>
36
     */
37
    public function getEvents(): array
38
    {
39
        return [
40
            new Event('topic', [$this->channel, $this->topic]),
41
        ];
42
    }
43
}
44