Passed
Push — master ( b1e531...74002f )
by Jeroen
01:49
created

IrcMessage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A handle() 0 4 3
A getEvents() 0 3 1
1
<?php
2
3
namespace Jerodev\PhpIrcClient\Messages;
4
5
use Jerodev\PhpIrcClient\Helpers\Event;
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 events that should be invoked for this message.
57
     *
58
     *  @return Event[]
59
     */
60
    public function getEvents(): array
61
    {
62
        return [];
63
    }
64
}
65