Completed
Push — master ( 7c39f2...831177 )
by Jeroen
04:12
created

IrcMessage::getRaw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
use Jerodev\PhpIrcClient\IrcClient;
6
7
class IrcMessage
8
{
9
    /** @var string */
10
    private $rawMessage;
11
12
    /** @var string */
13
    public $command;
14
15
    /** @var string */
16
    public $commandsuffix;
17
    
18
    /** @var bool */
19
    protected $handled;
20
21
    /** @var string */
22
    public $payload;
23
24
    /** @var string */
25
    public $source;
26
27
    public function __construct(string $message)
28
    {
29
        $this->handled = false;
30
        $this->rawMessage = $message;
31
32
        if (preg_match('/^(?::(?<source>[^\s]+)\s*)?(?<command>[^\s]+)\s*(?<commandsuffix>[^:$]+)?\s*(?::(?<payload>.*?))?$/', $message, $matches)) {
33
            $this->source = $matches['source'] ?? null;
34
            $this->command = $matches['command'] ?? null;
35
            $this->commandsuffix = trim($matches['commandsuffix'] ?? null);
36
            $this->payload = $matches['payload'] ?? null;
37
        }
38
    }
39
40
    /**
41
     *  Get the raw message line.
42
     *
43
     *  @return string
44
     */
45
    public function getRaw(): string
46
    {
47
        return $this->rawMessage;
48
    }
49
    
50
    /**
51
     *  This function is always called after the message is parsed.
52
     *  The handle will only be executed once unless forced.
53
     *
54
     *  @param IrcClient $client A reference to the irc client object
55
     *  @param bool $force Force handling this message even if already handled.
56
     */
57
    public function handle(IrcClient $client, bool $force = false): void
0 ignored issues
show
Unused Code introduced by
The parameter $client is not used and could be removed. ( Ignorable by Annotation )

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

57
    public function handle(/** @scrutinizer ignore-unused */ IrcClient $client, bool $force = false): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        if ($this->handled && !$force) {
60
            return;
61
        }
62
    }
63
}
64