Completed
Push — master ( ac9c3e...191d3f )
by Jeroen
01:42
created

IrcMessage::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
class IrcMessage
6
{
7
    /** @var string */
8
    private $rawMessage;
9
10
    /** @var string */
11
    public $command;
12
13
    /** @var string */
14
    public $commandsuffix;
15
16
    /** @var string */
17
    public $payload;
18
19
    /** @var string */
20
    public $source;
21
22
    public function __construct(string $message)
23
    {
24
        $this->rawMessage = $message;
25
26
        if (preg_match('/^(?::(?<source>[^\s]+)\s*)?(?<command>[^\s]+)\s*(?<commandsuffix>[^:$]+)?\s*(?::(?<payload>.*?))?$/', $message, $matches)) {
27
            $this->source = $matches['source'] ?? null;
28
            $this->command = $matches['command'] ?? null;
29
            $this->commandsuffix = trim($matches['commandsuffix'] ?? null);
30
            $this->payload = $matches['payload'] ?? null;
31
        }
32
    }
33
34
    /**
35
     *  Get the raw message line.
36
     *
37
     *  @return string
38
     */
39
    public function getRaw(): string
40
    {
41
        return $this->rawMessage;
42
    }
43
}
44