@@ -14,18 +14,18 @@ |
||
| 14 | 14 | * @param string $event The event that is being emitted. |
| 15 | 15 | * @param array $arguments The array of arguments to send to the event callback. |
| 16 | 16 | */ |
| 17 | - public function __construct(string $event, $arguments = []) |
|
| 17 | + public function __construct (string $event, $arguments = []) |
|
| 18 | 18 | { |
| 19 | 19 | $this->event = $event; |
| 20 | 20 | $this->arguments = $arguments; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function getArguments(): array |
|
| 23 | + public function getArguments (): array |
|
| 24 | 24 | { |
| 25 | 25 | return $this->arguments; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function getEvent(): string |
|
| 28 | + public function getEvent (): string |
|
| 29 | 29 | { |
| 30 | 30 | return $this->event; |
| 31 | 31 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** @var string[] */ |
| 14 | 14 | private $users; |
| 15 | 15 | |
| 16 | - public function __construct(string $name) |
|
| 16 | + public function __construct (string $name) |
|
| 17 | 17 | { |
| 18 | 18 | $name = trim($name); |
| 19 | 19 | if (empty($name)) { |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function getName(): string |
|
| 35 | + public function getName (): string |
|
| 36 | 36 | { |
| 37 | 37 | return $this->name; |
| 38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return null|string |
| 44 | 44 | */ |
| 45 | - public function getTopic() |
|
| 45 | + public function getTopic () |
|
| 46 | 46 | { |
| 47 | 47 | return $this->topic; |
| 48 | 48 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return string[] |
| 54 | 54 | */ |
| 55 | - public function getUsers(): array |
|
| 55 | + public function getUsers (): array |
|
| 56 | 56 | { |
| 57 | 57 | return $this->users; |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @param string $topic The topic |
| 64 | 64 | */ |
| 65 | - public function setTopic(string $topic): void |
|
| 65 | + public function setTopic (string $topic): void |
|
| 66 | 66 | { |
| 67 | 67 | $this->topic = $topic; |
| 68 | 68 | } |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @param string[] $users An array of user names. |
| 75 | 75 | */ |
| 76 | - public function setUsers(array $users): void |
|
| 76 | + public function setUsers (array $users): void |
|
| 77 | 77 | { |
| 78 | - $this->users = array_map(function ($user) { |
|
| 78 | + $this->users = array_map(function($user) { |
|
| 79 | 79 | if (in_array($user[0], ['+', '@'])) { |
| 80 | 80 | $user = substr($user, 1); |
| 81 | 81 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return Generator|IrcMessage[] |
| 23 | 23 | */ |
| 24 | - public function parse(string $message) |
|
| 24 | + public function parse (string $message) |
|
| 25 | 25 | { |
| 26 | 26 | foreach (explode("\n", $message) as $msg) { |
| 27 | 27 | if (empty(trim($msg))) { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return IrcMessage |
| 41 | 41 | */ |
| 42 | - private function parseSingle(string $message): IrcMessage |
|
| 42 | + private function parseSingle (string $message): IrcMessage |
|
| 43 | 43 | { |
| 44 | 44 | switch ($this->getCommand($message)) { |
| 45 | 45 | case 'KICK': |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return string |
| 88 | 88 | */ |
| 89 | - private function getCommand(string $message): string |
|
| 89 | + private function getCommand (string $message): string |
|
| 90 | 90 | { |
| 91 | 91 | if ($message[0] === ':') { |
| 92 | 92 | $message = trim(strstr($message, ' ')); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param string $nickname The nickname used on the irc server. |
| 44 | 44 | * @param string|string[] $channels The channels to join on connection. |
| 45 | 45 | */ |
| 46 | - public function __construct(?string $nickname = null, $channels = []) |
|
| 46 | + public function __construct (?string $nickname = null, $channels = []) |
|
| 47 | 47 | { |
| 48 | 48 | $this->nickname = $nickname; |
| 49 | 49 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * @return ConnectionOptions |
| 63 | 63 | */ |
| 64 | - public function connectionOptions(): ConnectionOptions |
|
| 64 | + public function connectionOptions (): ConnectionOptions |
|
| 65 | 65 | { |
| 66 | 66 | $options = new ConnectionOptions(); |
| 67 | 67 | $options->floodProtectionDelay = $this->floodProtectionDelay; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param string $server The server address to connect to including the port: `address:port`. |
| 34 | 34 | * @param ClientOptions $options An object depicting options for this connection. |
| 35 | 35 | */ |
| 36 | - public function __construct(string $server, ?ClientOptions $options = null) |
|
| 36 | + public function __construct (string $server, ?ClientOptions $options = null) |
|
| 37 | 37 | { |
| 38 | 38 | $this->options = $options ?? new ClientOptions(); |
| 39 | 39 | $this->connection = new IrcConnection($server, $this->options->connectionOptions()); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @param IrcUser|string $user The user information. |
| 61 | 61 | */ |
| 62 | - public function setUser($user): void |
|
| 62 | + public function setUser ($user): void |
|
| 63 | 63 | { |
| 64 | 64 | if (is_string($user)) { |
| 65 | 65 | $user = new IrcUser($user); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @throws Exception if no user information is provided before connecting. |
| 79 | 79 | */ |
| 80 | - public function connect(): void |
|
| 80 | + public function connect (): void |
|
| 81 | 81 | { |
| 82 | 82 | if (!$this->user) { |
| 83 | 83 | throw new Exception('A nickname must be set before connecting to an irc server.'); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $this->isAuthenticated = false; |
| 91 | - $this->connection->onData(function ($msg) { |
|
| 91 | + $this->connection->onData(function($msg) { |
|
| 92 | 92 | $this->handleIrcMessage($msg); |
| 93 | 93 | }); |
| 94 | 94 | $this->connection->open(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | /** |
| 98 | 98 | * Close the current connection, if any. |
| 99 | 99 | */ |
| 100 | - public function disconnect(): void |
|
| 100 | + public function disconnect (): void |
|
| 101 | 101 | { |
| 102 | 102 | $this->connection->close(); |
| 103 | 103 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param string $event The event to register to. |
| 109 | 109 | * @param callable $callback The callback to be execute when the event is emitted. |
| 110 | 110 | */ |
| 111 | - public function on(string $event, callable $callback): void |
|
| 111 | + public function on (string $event, callable $callback): void |
|
| 112 | 112 | { |
| 113 | 113 | $this->messageEventHandlers->addHandler($event, $callback); |
| 114 | 114 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @param string $command The full command string to send. |
| 120 | 120 | */ |
| 121 | - public function send(string $command): void |
|
| 121 | + public function send (string $command): void |
|
| 122 | 122 | { |
| 123 | 123 | $this->connection->write($command); |
| 124 | 124 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @param string $target The channel or user to message. |
| 131 | 131 | * @param string $message The message to send. |
| 132 | 132 | */ |
| 133 | - public function say(string $target, string $message): void |
|
| 133 | + public function say (string $target, string $message): void |
|
| 134 | 134 | { |
| 135 | 135 | foreach (explode("\n", $message) as $msg) { |
| 136 | 136 | $this->send("PRIVMSG $target :" . trim($msg)); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @param string $channel The name of the channel to join. |
| 144 | 144 | */ |
| 145 | - public function join(string $channel): void |
|
| 145 | + public function join (string $channel): void |
|
| 146 | 146 | { |
| 147 | 147 | $channel = $this->channelName($channel); |
| 148 | 148 | $this->send("JOIN $channel"); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * |
| 155 | 155 | * @param string $channel The name of the channel to leave. |
| 156 | 156 | */ |
| 157 | - public function part(string $channel): void |
|
| 157 | + public function part (string $channel): void |
|
| 158 | 158 | { |
| 159 | 159 | $channel = $this->channelName($channel); |
| 160 | 160 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return IrcChannel |
| 173 | 173 | */ |
| 174 | - public function getChannel(string $channel): IrcChannel |
|
| 174 | + public function getChannel (string $channel): IrcChannel |
|
| 175 | 175 | { |
| 176 | 176 | $channel = $this->channelName($channel); |
| 177 | 177 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @var string |
| 189 | 189 | */ |
| 190 | - public function getNickname(): string |
|
| 190 | + public function getNickname (): string |
|
| 191 | 191 | { |
| 192 | 192 | return $this->user->nickname; |
| 193 | 193 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * |
| 198 | 198 | * @return IrcChannel[] |
| 199 | 199 | */ |
| 200 | - public function getChannels(): array |
|
| 200 | + public function getChannels (): array |
|
| 201 | 201 | { |
| 202 | 202 | return $this->channels; |
| 203 | 203 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | - public function shouldAutoRejoin(): bool |
|
| 210 | + public function shouldAutoRejoin (): bool |
|
| 211 | 211 | { |
| 212 | 212 | return $this->options->autoRejoin; |
| 213 | 213 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @param IrcMessage $message The message object for the received line. |
| 219 | 219 | */ |
| 220 | - private function handleIrcMessage(IrcMessage $message): void |
|
| 220 | + private function handleIrcMessage (IrcMessage $message): void |
|
| 221 | 221 | { |
| 222 | 222 | $message->injectChannel($this->channels); |
| 223 | 223 | $message->handle($this); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return string The formatted name. |
| 242 | 242 | */ |
| 243 | - private function channelName(string $channel): string |
|
| 243 | + private function channelName (string $channel): string |
|
| 244 | 244 | { |
| 245 | 245 | if ($channel[0] !== '#') { |
| 246 | 246 | $channel = "#$channel"; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** @var string */ |
| 21 | 21 | public $user; |
| 22 | 22 | |
| 23 | - public function __construct(string $message) |
|
| 23 | + public function __construct (string $message) |
|
| 24 | 24 | { |
| 25 | 25 | parent::__construct($message); |
| 26 | 26 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * When the bot is kicked form a channel, it might need to auto rejoin. |
| 33 | 33 | */ |
| 34 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 34 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 35 | 35 | { |
| 36 | 36 | if ($this->handled && !$force) { |
| 37 | 37 | return; |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function getEvents(): array |
|
| 45 | + public function getEvents (): array |
|
| 46 | 46 | { |
| 47 | 47 | return [ |
| 48 | 48 | new Event('kick', [$this->channel, $this->user, $this->message]), |
| 49 | 49 | ]; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public function injectChannel(array $channels): void |
|
| 52 | + public function injectChannel (array $channels): void |
|
| 53 | 53 | { |
| 54 | 54 | if (array_key_exists($this->target, $channels)) { |
| 55 | 55 | $this->channel = $channels[$this->target]; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** @var string */ |
| 37 | 37 | private $server; |
| 38 | 38 | |
| 39 | - public function __construct(string $server, ?ConnectionOptions $options = null) |
|
| 39 | + public function __construct (string $server, ?ConnectionOptions $options = null) |
|
| 40 | 40 | { |
| 41 | 41 | $options = $options ?? new ConnectionOptions(); |
| 42 | 42 | $this->server = $server; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->messageQueue = []; |
| 50 | 50 | |
| 51 | 51 | if ($this->floodProtected) { |
| 52 | - $this->loop->addPeriodicTimer($options->floodProtectionDelay / 1000, function () { |
|
| 52 | + $this->loop->addPeriodicTimer($options->floodProtectionDelay / 1000, function() { |
|
| 53 | 53 | if ($msg = array_shift($this->messageQueue)) { |
| 54 | 54 | $this->connection->write($msg); |
| 55 | 55 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Open a connection to the irc server. |
| 62 | 62 | */ |
| 63 | - public function open() |
|
| 63 | + public function open () |
|
| 64 | 64 | { |
| 65 | 65 | if ($this->isConnected()) { |
| 66 | 66 | return; |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | $dns = $dnsResolverFactory->createCached('1.1.1.1', $this->loop); |
| 72 | 72 | $dnsConnector = new \React\Socket\DnsConnector($tcpConnector, $dns); |
| 73 | 73 | |
| 74 | - $dnsConnector->connect($this->server)->then(function (ConnectionInterface $connection) { |
|
| 74 | + $dnsConnector->connect($this->server)->then(function(ConnectionInterface $connection) { |
|
| 75 | 75 | $this->connection = $connection; |
| 76 | 76 | $this->connected = true; |
| 77 | 77 | |
| 78 | - $this->connection->on('data', function ($data) { |
|
| 78 | + $this->connection->on('data', function($data) { |
|
| 79 | 79 | foreach ($this->messageParser->parse($data) as $msg) { |
| 80 | 80 | $this->handleMessage($msg); |
| 81 | 81 | } |
| 82 | 82 | }); |
| 83 | 83 | |
| 84 | - $this->connection->on('close', function () { |
|
| 84 | + $this->connection->on('close', function() { |
|
| 85 | 85 | $this->connected = false; |
| 86 | 86 | }); |
| 87 | - $this->connection->on('end', function () { |
|
| 87 | + $this->connection->on('end', function() { |
|
| 88 | 88 | $this->connected = false; |
| 89 | 89 | }); |
| 90 | 90 | }); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * Close the current irc server connection. |
| 97 | 97 | */ |
| 98 | - public function close(): void |
|
| 98 | + public function close (): void |
|
| 99 | 99 | { |
| 100 | 100 | if ($this->isConnected()) { |
| 101 | 101 | $this->connection->close(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | /** |
| 107 | 107 | * Test if there is an open connection to the irc server. |
| 108 | 108 | */ |
| 109 | - public function isConnected(): bool |
|
| 109 | + public function isConnected (): bool |
|
| 110 | 110 | { |
| 111 | 111 | return $this->connection && $this->connected; |
| 112 | 112 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @param callable $function The function to be called. |
| 119 | 119 | */ |
| 120 | - public function onData(callable $function): void |
|
| 120 | + public function onData (callable $function): void |
|
| 121 | 121 | { |
| 122 | 122 | $this->eventHandlerCollection->addHandler('data', $function); |
| 123 | 123 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @throws Exception if no open connection is available. |
| 131 | 131 | */ |
| 132 | - public function write(string $command): void |
|
| 132 | + public function write (string $command): void |
|
| 133 | 133 | { |
| 134 | 134 | if (!$this->isConnected()) { |
| 135 | 135 | throw new Exception('No open connection was found to write commands to.'); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param IrcMessage $message The message received from the server. |
| 154 | 154 | */ |
| 155 | - private function handleMessage(IrcMessage $message): void |
|
| 155 | + private function handleMessage (IrcMessage $message): void |
|
| 156 | 156 | { |
| 157 | 157 | $this->eventHandlerCollection->invoke(new Event('data', [$message])); |
| 158 | 158 | } |