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

TopicChangeMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 7 3
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 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