Passed
Push — master ( 831177...1585b1 )
by Jeroen
01:32
created

IrcMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A handle() 0 4 3
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
    protected $command;
14
15
    /** @var string */
16
    protected $commandsuffix;
17
    
18
    /** @var bool */
19
    protected $handled;
20
21
    /** @var string */
22
    protected $payload;
23
24
    /** @var string */
25
    protected $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
     *  This function is always called after the message is parsed.
42
     *  The handle will only be executed once unless forced.
43
     *
44
     *  @param IrcClient $client A reference to the irc client object
45
     *  @param bool $force Force handling this message even if already handled.
46
     */
47
    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

47
    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...
48
    {
49
        if ($this->handled && !$force) {
50
            return;
51
        }
52
    }
53
}
54