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

IrcMessage::getEventArgs()   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\Helpers\EventArgs;
6
use Jerodev\PhpIrcClient\IrcClient;
7
8
class IrcMessage
9
{
10
    /** @var string */
11
    private $rawMessage;
12
13
    /** @var string */
14
    protected $command;
15
16
    /** @var string */
17
    protected $commandsuffix;
18
19
    /** @var bool */
20
    protected $handled;
21
22
    /** @var string */
23
    protected $payload;
24
25
    /** @var string */
26
    protected $source;
27
28
    public function __construct(string $message)
29
    {
30
        $this->handled = false;
31
        $this->rawMessage = $message;
32
33
        if (preg_match('/^(?::(?<source>[^\s]+)\s*)?(?<command>[^\s]+)\s*(?<commandsuffix>[^:$]+)?\s*(?::(?<payload>.*?))?$/', $message, $matches)) {
34
            $this->source = $matches['source'] ?? null;
35
            $this->command = $matches['command'] ?? null;
36
            $this->commandsuffix = trim($matches['commandsuffix'] ?? null);
37
            $this->payload = $matches['payload'] ?? null;
38
        }
39
    }
40
41
    /**
42
     *  This function is always called after the message is parsed.
43
     *  The handle will only be executed once unless forced.
44
     *
45
     *  @param IrcClient $client A reference to the irc client object
46
     *  @param bool $force Force handling this message even if already handled.
47
     */
48
    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

48
    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...
49
    {
50
        if ($this->handled && !$force) {
51
            return;
52
        }
53
    }
54
55
    /**
56
     *  Get the arguments needed for the event callback for this message.
57
     *
58
     *  @return EventArgs[] An array of event args to emit.
59
     */
60
    public function getEventArgs(): array
61
    {
62
        return [];
63
    }
64
}
65