Passed
Pull Request — master (#12)
by
unknown
08:46
created
src/Messages/PrivmsgMessage.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,18 +12,18 @@
 block discarded – undo
12 12
     public string $message;
13 13
     public string $user;
14 14
 
15
-    public function __construct(string $message)
15
+    public function __construct (string $message)
16 16
     {
17 17
         parent::__construct($message);
18 18
         $this->user = strstr($this->source ?? '', '!', true);
19
-        $this->target = (string)$this->commandsuffix;
19
+        $this->target = (string) $this->commandsuffix;
20 20
         $this->message = $this->payload;
21 21
     }
22 22
 
23 23
     /**
24 24
      * @return array<int, Event>
25 25
      */
26
-    public function getEvents(): array
26
+    public function getEvents (): array
27 27
     {
28 28
         if ($this->target[0] === '#') {
29 29
             return [
Please login to merge, or discard this patch.
src/Messages/ModeMessage.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     public ?string $target = null;
15 15
     public string $user;
16 16
 
17
-    public function __construct(string $command)
17
+    public function __construct (string $command)
18 18
     {
19 19
         parent::__construct($command);
20 20
         if ('#' === $this->commandsuffix[0]) {
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * @return array<int, Event>
32 32
      */
33
-    public function getEvents(): array
33
+    public function getEvents (): array
34 34
     {
35 35
         return [
36 36
             new Event('mode', [$this->channel, $this->user, $this->mode]),
Please login to merge, or discard this patch.
src/IrcConnection.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     /** @var array<int, string> */
25 25
     private array $messageQueue = [];
26 26
 
27
-    public function __construct(
27
+    public function __construct (
28 28
         private string $server,
29 29
         ?ConnectionOptions $options = null
30 30
     ) {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         $this->messageParser = new IrcMessageParser();
37 37
 
38 38
         if ($this->floodProtected) {
39
-            $this->loop->addPeriodicTimer($options->floodProtectionDelay / 1000, function () {
39
+            $this->loop->addPeriodicTimer($options->floodProtectionDelay / 1000, function() {
40 40
                 if ($msg = array_shift($this->messageQueue)) {
41 41
                     $this->connection->write($msg);
42 42
                 }
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * Open a connection to the IRC server.
49 49
      */
50
-    public function open(): void
50
+    public function open (): void
51 51
     {
52 52
         if ($this->isConnected()) {
53 53
             return;
@@ -58,20 +58,20 @@  discard block
 block discarded – undo
58 58
         $dns = $dnsResolverFactory->createCached('1.1.1.1', $this->loop);
59 59
         $dnsConnector = new \React\Socket\DnsConnector($tcpConnector, $dns);
60 60
 
61
-        $dnsConnector->connect($this->server)->then(function (ConnectionInterface $connection) {
61
+        $dnsConnector->connect($this->server)->then(function(ConnectionInterface $connection) {
62 62
             $this->connection = $connection;
63 63
             $this->connected = true;
64 64
 
65
-            $this->connection->on('data', function ($data) {
65
+            $this->connection->on('data', function($data) {
66 66
                 foreach ($this->messageParser->parse($data) as $msg) {
67 67
                     $this->handleMessage($msg);
68 68
                 }
69 69
             });
70 70
 
71
-            $this->connection->on('close', function () {
71
+            $this->connection->on('close', function() {
72 72
                 $this->connected = false;
73 73
             });
74
-            $this->connection->on('end', function () {
74
+            $this->connection->on('end', function() {
75 75
                 $this->connected = false;
76 76
             });
77 77
         });
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * Close the current IRC server connection.
84 84
      */
85
-    public function close(): void
85
+    public function close (): void
86 86
     {
87 87
         if ($this->isConnected()) {
88 88
             $this->connection->close();
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     /**
94 94
      * Test if there is an open connection to the IRC server.
95 95
      */
96
-    public function isConnected(): bool
96
+    public function isConnected (): bool
97 97
     {
98 98
         return $this->connection && $this->connected;
99 99
     }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      * An IrcMessage object will be passed to the callback.
104 104
      * @param callable $function The function to be called.
105 105
      */
106
-    public function onData(callable $function): void
106
+    public function onData (callable $function): void
107 107
     {
108 108
         $this->eventHandlerCollection->addHandler('data', $function);
109 109
     }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      * @param string $command The raw IRC command.
114 114
      * @throws Exception if no open connection is available.
115 115
      */
116
-    public function write(string $command): void
116
+    public function write (string $command): void
117 117
     {
118 118
         if (!$this->isConnected()) {
119 119
             throw new Exception('No open connection was found to write commands to.');
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
     /**
135 135
      * Handle a single parsed IrcMessage.
136 136
      */
137
-    private function handleMessage(IrcMessage $message): void
137
+    private function handleMessage (IrcMessage $message): void
138 138
     {
139 139
         $this->eventHandlerCollection->invoke(new Event('data', [$message]));
140 140
     }
141 141
 
142
-    public function getServer(): string
142
+    public function getServer (): string
143 143
     {
144 144
         return $this->server;
145 145
     }
Please login to merge, or discard this patch.
src/IrcMessageParser.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * @param string $message A string received from the IRC server
25 25
      * @return Generator|IrcMessage[]
26 26
      */
27
-    public function parse(string $message)
27
+    public function parse (string $message)
28 28
     {
29 29
         foreach (explode("\n", $message) as $msg) {
30 30
             if ('' === trim($msg)) {
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * Parse a single message to a corresponding object.
40 40
      */
41
-    private function parseSingle(string $message): IrcMessage
41
+    private function parseSingle (string $message): IrcMessage
42 42
     {
43 43
         switch ($this->getCommand($message)) {
44 44
             case 'KICK':
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     /**
69 69
      * Get the COMMAND part of an IRC message.
70 70
      */
71
-    private function getCommand(string $message): bool | string
71
+    private function getCommand (string $message): bool | string
72 72
     {
73 73
         if ($message[0] === ':') {
74 74
             $message = trim(strstr($message, ' '));
Please login to merge, or discard this patch.
src/IrcChannel.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     /** @var array<int, string> */
15 15
     private array $users = [];
16 16
 
17
-    public function __construct(string $name)
17
+    public function __construct (string $name)
18 18
     {
19 19
         $name = trim($name);
20 20
         if ('' === $name || '#' === $name) {
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * Fetch the name of the channel, including the `#`.
32 32
      */
33
-    public function getName(): string
33
+    public function getName (): string
34 34
     {
35 35
         return $this->name;
36 36
     }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * Get the current channel topic.
40 40
      */
41
-    public function getTopic(): ?string
41
+    public function getTopic (): ?string
42 42
     {
43 43
         return $this->topic;
44 44
     }
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * Fetch the list of users currently on this channel.
48 48
      * @return array<int, string>
49 49
      */
50
-    public function getUsers(): array
50
+    public function getUsers (): array
51 51
     {
52 52
         return $this->users;
53 53
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * Set the current channel topic.
57 57
      * @param string $topic The topic
58 58
      */
59
-    public function setTopic(string $topic): void
59
+    public function setTopic (string $topic): void
60 60
     {
61 61
         $this->topic = $topic;
62 62
     }
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
      * User modes (`+`, `@`) will be removed from the nicknames.
67 67
      * @param array<int, string> $users An array of user names.
68 68
      */
69
-    public function setUsers(array $users): void
69
+    public function setUsers (array $users): void
70 70
     {
71
-        $this->users = array_map(function ($user): string {
71
+        $this->users = array_map(function($user): string {
72 72
             if (in_array($user[0], ['+', '@'])) {
73 73
                 $user = substr($user, 1);
74 74
             }
Please login to merge, or discard this patch.
src/IrcUser.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@
 block discarded – undo
6 6
 
7 7
 class IrcUser
8 8
 {
9
-    public function __construct(public string $nickname)
9
+    public function __construct (public string $nickname)
10 10
     {
11 11
     }
12 12
 
13
-    public function __toString(): string
13
+    public function __toString (): string
14 14
     {
15 15
         return $this->nickname;
16 16
     }
Please login to merge, or discard this patch.
src/Helpers/Event.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@
 block discarded – undo
10 10
      *  @param string $event The event that is being emitted.
11 11
      *  @param array $arguments The array of arguments to send to the event callback.
12 12
      */
13
-    public function __construct(private string $event, private array $arguments = [])
13
+    public function __construct (private string $event, private array $arguments = [])
14 14
     {
15 15
     }
16 16
 
17
-    public function getArguments(): array
17
+    public function getArguments (): array
18 18
     {
19 19
         return $this->arguments;
20 20
     }
21 21
 
22
-    public function getEvent(): string
22
+    public function getEvent (): string
23 23
     {
24 24
         return $this->event;
25 25
     }
Please login to merge, or discard this patch.
src/Helpers/EventHandlerCollection.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
      * @param callable|string $event The name of the event to listen for. Pass a callable to this parameter to catch all events.
16 16
      * @param callable|null $function The callable that will be invoked on event
17 17
      */
18
-    public function addHandler(
18
+    public function addHandler (
19 19
         callable | string $event,
20 20
         ?callable $function
21 21
     ): void {
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     /**
36 36
      *  Invoke all handlers for a specific event.
37 37
      */
38
-    public function invoke(Event $event): void
38
+    public function invoke (Event $event): void
39 39
     {
40 40
         $handlers = array_merge(
41 41
             $this->eventHandlers['*'] ?? [],
Please login to merge, or discard this patch.
src/IrcClient.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      * @param string $server The server address to connect to including the port: `address:port`.
26 26
      * @param ClientOptions $options An object depicting options for this connection.
27 27
      */
28
-    public function __construct(string $server, ?ClientOptions $options = null)
28
+    public function __construct (string $server, ?ClientOptions $options = null)
29 29
     {
30 30
         $this->options = $options ?? new ClientOptions();
31 31
         $this->connection = new IrcConnection($server, $this->options->connectionOptions());
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      * the nickname of the client.
54 54
      * @param IrcUser|string $user The user information.
55 55
      */
56
-    public function setUser(IrcUser | string $user): void
56
+    public function setUser (IrcUser | string $user): void
57 57
     {
58 58
         if (is_string($user)) {
59 59
             $user = new IrcUser($user);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * Connect to the irc server and start listening for messages.
71 71
      * @throws Exception if no user information is provided before connecting.
72 72
      */
73
-    public function connect(): void
73
+    public function connect (): void
74 74
     {
75 75
         if (!$this->user) {
76 76
             throw new Exception(
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         }
84 84
 
85 85
         $this->isAuthenticated = false;
86
-        $this->connection->onData(function (IrcMessage $msg): void {
86
+        $this->connection->onData(function(IrcMessage $msg): void {
87 87
             $this->handleIrcMessage($msg);
88 88
         });
89 89
         $this->connection->open();
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     /**
93 93
      * Close the current connection, if any.
94 94
      */
95
-    public function disconnect(): void
95
+    public function disconnect (): void
96 96
     {
97 97
         $this->connection->close();
98 98
     }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param string $event The event to register to.
103 103
      * @param callable $callback The callback to be execute when the event is emitted.
104 104
      */
105
-    public function on(string $event, callable $callback): void
105
+    public function on (string $event, callable $callback): void
106 106
     {
107 107
         $this->messageEventHandlers->addHandler($event, $callback);
108 108
     }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      * Send a raw command string to the IRC server.
112 112
      * @param string $command The full command string to send.
113 113
      */
114
-    public function send(string $command): void
114
+    public function send (string $command): void
115 115
     {
116 116
         $this->connection->write($command);
117 117
     }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param string $target The channel or user to message.
123 123
      * @param string $message The message to send.
124 124
      */
125
-    public function say(string $target, string $message): void
125
+    public function say (string $target, string $message): void
126 126
     {
127 127
         foreach (explode("\n", $message) as $msg) {
128 128
             $this->send("PRIVMSG $target :" . trim($msg));
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      * Join an IRC channel.
134 134
      * @param string $channel The name of the channel to join.
135 135
      */
136
-    public function join(string $channel): void
136
+    public function join (string $channel): void
137 137
     {
138 138
         $channel = $this->channelName($channel);
139 139
         $this->send("JOIN $channel");
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      * Part from an IRC channel.
145 145
      * @param string $channel The name of the channel to leave.
146 146
      */
147
-    public function part(string $channel): void
147
+    public function part (string $channel): void
148 148
     {
149 149
         $channel = $this->channelName($channel);
150 150
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * Grab channel information by its name.
158 158
      * This function makes sure the channel exists on this client first.
159 159
      */
160
-    public function getChannel(string $channel): IrcChannel
160
+    public function getChannel (string $channel): IrcChannel
161 161
     {
162 162
         $channel = $this->channelName($channel);
163 163
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     /**
172 172
      * Get the name with which the client is currently known on the server.
173 173
      */
174
-    public function getNickname(): ?string
174
+    public function getNickname (): ?string
175 175
     {
176 176
         if (null === $this->user) {
177 177
             return null;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      * Return a list of all channels.
184 184
      * @return array<string, IrcChannel>
185 185
      */
186
-    public function getChannels(): array
186
+    public function getChannels (): array
187 187
     {
188 188
         return $this->channels;
189 189
     }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     /**
192 192
      * Indicates whether the client should autorejoin channels when kicked.
193 193
      */
194
-    public function shouldAutoRejoin(): bool
194
+    public function shouldAutoRejoin (): bool
195 195
     {
196 196
         return $this->options->autoRejoin;
197 197
     }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      * event handlers.
202 202
      * @param IrcMessage $message The message object for the received line.
203 203
      */
204
-    private function handleIrcMessage(IrcMessage $message): void
204
+    private function handleIrcMessage (IrcMessage $message): void
205 205
     {
206 206
         $message->injectChannel($this->channels);
207 207
         $message->handle($this);
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     /**
221 221
      * Make sure all channel names have the same format.
222 222
      */
223
-    private function channelName(string $channel): string
223
+    private function channelName (string $channel): string
224 224
     {
225 225
         if ($channel[0] !== '#') {
226 226
             $channel = "#$channel";
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         return $channel;
230 230
     }
231 231
 
232
-    public function getConnection(): IrcConnection
232
+    public function getConnection (): IrcConnection
233 233
     {
234 234
         return $this->connection;
235 235
     }
Please login to merge, or discard this patch.