1 | <?php |
||||
2 | |||||
3 | namespace Jerodev\PhpIrcClient\Messages; |
||||
4 | |||||
5 | use Jerodev\PhpIrcClient\Helpers\Event; |
||||
6 | use Jerodev\PhpIrcClient\IrcChannel; |
||||
7 | use Jerodev\PhpIrcClient\IrcClient; |
||||
8 | |||||
9 | class IrcMessage |
||||
10 | { |
||||
11 | /** @var string */ |
||||
12 | private $rawMessage; |
||||
13 | |||||
14 | /** @var string */ |
||||
15 | protected $command; |
||||
16 | |||||
17 | /** @var string */ |
||||
18 | protected $commandsuffix; |
||||
19 | |||||
20 | /** @var bool */ |
||||
21 | protected $handled; |
||||
22 | |||||
23 | /** @var string */ |
||||
24 | protected $payload; |
||||
25 | |||||
26 | /** @var string */ |
||||
27 | protected $source; |
||||
28 | |||||
29 | public function __construct(string $command) |
||||
30 | { |
||||
31 | $this->handled = false; |
||||
32 | $this->parse($command); |
||||
33 | } |
||||
34 | |||||
35 | /** |
||||
36 | * This function is always called after the message is parsed. |
||||
37 | * The handle will only be executed once unless forced. |
||||
38 | * |
||||
39 | * @param IrcClient $client A reference to the irc client object |
||||
40 | * @param bool $force Force handling this message even if already handled. |
||||
41 | */ |
||||
42 | public function handle(IrcClient $client, bool $force = false): void |
||||
0 ignored issues
–
show
|
|||||
43 | { |
||||
44 | if ($this->handled && !$force) { |
||||
45 | return; |
||||
46 | } |
||||
47 | } |
||||
48 | |||||
49 | /** |
||||
50 | * Get the events that should be invoked for this message. |
||||
51 | * |
||||
52 | * @return Event[] |
||||
53 | */ |
||||
54 | public function getEvents() |
||||
55 | { |
||||
56 | return []; |
||||
57 | } |
||||
58 | |||||
59 | /** |
||||
60 | * Inject the list of irc channels. |
||||
61 | * The messages can use this to gather information of the channel if needed. |
||||
62 | * |
||||
63 | * @param IrcChannel[] $channels The list of irc channels in the IrcClient. |
||||
64 | */ |
||||
65 | public function injectChannel(array $channels): void |
||||
0 ignored issues
–
show
The parameter
$channels 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
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
66 | { |
||||
67 | // |
||||
68 | } |
||||
69 | |||||
70 | /** |
||||
71 | * Parse the irc command string to local properties. |
||||
72 | * |
||||
73 | * @param string $command |
||||
74 | */ |
||||
75 | private function parse(string $command): void |
||||
76 | { |
||||
77 | $command = trim($command); |
||||
78 | $this->rawMessage = $command; |
||||
79 | $i = 0; |
||||
80 | |||||
81 | if ($command[0] === ':') { |
||||
82 | $i = strpos($command, ' '); |
||||
83 | $this->source = substr($command, 1, $i - 1); |
||||
84 | |||||
85 | $i++; |
||||
86 | } |
||||
87 | |||||
88 | $j = strpos($command, ' ', $i); |
||||
89 | if ($j !== false) { |
||||
90 | $this->command = substr($command, $i, $j - $i); |
||||
91 | } else { |
||||
92 | $this->command = substr($command, $i); |
||||
93 | |||||
94 | return; |
||||
95 | } |
||||
96 | |||||
97 | $i = strpos($command, ':', $j); |
||||
98 | if ($i !== false) { |
||||
99 | if ($i !== $j + 1) { |
||||
100 | $this->commandsuffix = substr($command, $j + 1, $i - $j - 2); |
||||
101 | } |
||||
102 | $this->payload = substr($command, $i + 1); |
||||
103 | } else { |
||||
104 | $this->commandsuffix = substr($command, $j + 1); |
||||
105 | } |
||||
106 | } |
||||
107 | } |
||||
108 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.