Completed
Push — master ( 57883c...b5af1c )
by Jeroen
01:44
created

NameReplyMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
use Jerodev\PhpIrcClient\Helpers\EventArgs;
6
use Jerodev\PhpIrcClient\IrcClient;
7
8
class NameReplyMessage extends IrcMessage
9
{
10
    /** @var string */
11
    public $channel;
12
13
    /** @var string[] */
14
    public $names;
15
16
    public function __construct(string $message)
17
    {
18
        parent::__construct($message);
19
20
        $this->channel = preg_replace('/^[^\#]+(\#.*?)$/', '$1', $this->commandsuffix);
21
        $this->names = preg_split('/\s+/', $this->payload, -1, PREG_SPLIT_NO_EMPTY);
0 ignored issues
show
Documentation Bug introduced by
It seems like preg_split('/\s+/', $thi...es\PREG_SPLIT_NO_EMPTY) of type false is incompatible with the declared type string[] of property $names.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
    }
23
24
    public function handle(IrcClient $client, bool $force = false): void
25
    {
26
        if ($this->handled && !$force) {
27
            return;
28
        }
29
30
        $client->getChannel($this->channel)->setUsers($this->names);
31
    }
32
33
    public function getEventArgs(): array
34
    {
35
        return [
36
            new EventArgs('names', [$this->channel, $this->names]),
37
            new EventArgs("names#$this->channel", [$this->names])
38
        ];
39
    }
40
}
41