@@ -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,27 +60,27 @@ 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 | $tcpConnector = new \React\Socket\TcpConnector($this->loop); |
| 66 | 66 | $dnsResolverFactory = new \React\Dns\Resolver\Factory(); |
| 67 | 67 | $dns = $dnsResolverFactory->createCached('1.1.1.1', $this->loop); |
| 68 | 68 | $dnsConnector = new \React\Socket\DnsConnector($tcpConnector, $dns); |
| 69 | 69 | |
| 70 | - $dnsConnector->connect($this->server)->then(function (ConnectionInterface $connection) { |
|
| 70 | + $dnsConnector->connect($this->server)->then(function(ConnectionInterface $connection) { |
|
| 71 | 71 | $this->connection = $connection; |
| 72 | 72 | $this->connected = true; |
| 73 | 73 | |
| 74 | - $this->connection->on('data', function ($data) { |
|
| 74 | + $this->connection->on('data', function($data) { |
|
| 75 | 75 | foreach ($this->messageParser->parse($data) as $msg) { |
| 76 | 76 | $this->handleMessage($msg); |
| 77 | 77 | } |
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | - $this->connection->on('close', function () { |
|
| 80 | + $this->connection->on('close', function() { |
|
| 81 | 81 | $this->connected = false; |
| 82 | 82 | }); |
| 83 | - $this->connection->on('end', function () { |
|
| 83 | + $this->connection->on('end', function() { |
|
| 84 | 84 | $this->connected = false; |
| 85 | 85 | }); |
| 86 | 86 | }); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * Close the current irc server connection. |
| 93 | 93 | */ |
| 94 | - public function close(): void |
|
| 94 | + public function close (): void |
|
| 95 | 95 | { |
| 96 | 96 | if ($this->isConnected()) { |
| 97 | 97 | $this->connection->close(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * Test if there is an open connection to the irc server. |
| 104 | 104 | */ |
| 105 | - public function isConnected(): bool |
|
| 105 | + public function isConnected (): bool |
|
| 106 | 106 | { |
| 107 | 107 | return $this->connection && $this->connected; |
| 108 | 108 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @param callable $function The function to be called. |
| 115 | 115 | */ |
| 116 | - public function onData(callable $function): void |
|
| 116 | + public function onData (callable $function): void |
|
| 117 | 117 | { |
| 118 | 118 | $this->eventHandlerCollection->addHandler('data', $function); |
| 119 | 119 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @throws Exception if no open connection is available. |
| 127 | 127 | */ |
| 128 | - public function write(string $command): void |
|
| 128 | + public function write (string $command): void |
|
| 129 | 129 | { |
| 130 | 130 | if (!$this->isConnected()) { |
| 131 | 131 | throw new Exception('No open connection was found to write commands to.'); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @param IrcMessage $message The message received from the server. |
| 150 | 150 | */ |
| 151 | - private function handleMessage(IrcMessage $message): void |
|
| 151 | + private function handleMessage (IrcMessage $message): void |
|
| 152 | 152 | { |
| 153 | 153 | $this->eventHandlerCollection->invoke(new Event('data', [$message])); |
| 154 | 154 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** @var string */ |
| 27 | 27 | protected $source; |
| 28 | 28 | |
| 29 | - public function __construct(string $command) |
|
| 29 | + public function __construct (string $command) |
|
| 30 | 30 | { |
| 31 | 31 | $this->handled = false; |
| 32 | 32 | $this->parse($command); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param IrcClient $client A reference to the irc client object |
| 40 | 40 | * @param bool $force Force handling this message even if already handled. |
| 41 | 41 | */ |
| 42 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 42 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 43 | 43 | { |
| 44 | 44 | if ($this->handled && !$force) { |
| 45 | 45 | return; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return Event[] |
| 53 | 53 | */ |
| 54 | - public function getEvents() |
|
| 54 | + public function getEvents () |
|
| 55 | 55 | { |
| 56 | 56 | return []; |
| 57 | 57 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @param IrcChannel[] $channels The list of irc channels in the IrcClient. |
| 64 | 64 | */ |
| 65 | - public function injectChannel(array $channels): void |
|
| 65 | + public function injectChannel (array $channels): void |
|
| 66 | 66 | { |
| 67 | 67 | // |
| 68 | 68 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param string $command |
| 74 | 74 | */ |
| 75 | - private function parse(string $command): void |
|
| 75 | + private function parse (string $command): void |
|
| 76 | 76 | { |
| 77 | 77 | $command = trim($command); |
| 78 | 78 | $this->rawMessage = $command; |
@@ -6,12 +6,12 @@ |
||
| 6 | 6 | |
| 7 | 7 | class MOTDMessage extends IrcMessage |
| 8 | 8 | { |
| 9 | - public function __construct(string $message) |
|
| 9 | + public function __construct (string $message) |
|
| 10 | 10 | { |
| 11 | 11 | parent::__construct($message); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function getEvents(): array |
|
| 14 | + public function getEvents (): array |
|
| 15 | 15 | { |
| 16 | 16 | return [ |
| 17 | 17 | new Event('motd', [$this->payload]), |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class PingMessage extends IrcMessage |
| 9 | 9 | { |
| 10 | - public function __construct(string $message) |
|
| 10 | + public function __construct (string $message) |
|
| 11 | 11 | { |
| 12 | 12 | parent::__construct($message); |
| 13 | 13 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * Reply the ping message with a pong response. |
| 17 | 17 | */ |
| 18 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 18 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 19 | 19 | { |
| 20 | 20 | if ($this->handled && !$force) { |
| 21 | 21 | return; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $client->send("PONG :$this->payload"); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function getEvents(): array |
|
| 27 | + public function getEvents (): array |
|
| 28 | 28 | { |
| 29 | 29 | return [ |
| 30 | 30 | new Event('ping'), |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** @var string */ |
| 17 | 17 | public $user; |
| 18 | 18 | |
| 19 | - public function __construct(string $message) |
|
| 19 | + public function __construct (string $message) |
|
| 20 | 20 | { |
| 21 | 21 | parent::__construct($message); |
| 22 | 22 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * Change the topic for the referenced channel. |
| 29 | 29 | */ |
| 30 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 30 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 31 | 31 | { |
| 32 | 32 | if ($this->handled && !$force) { |
| 33 | 33 | return; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $client->getChannel($this->channel)->setTopic($this->topic); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function getEvents(): array |
|
| 39 | + public function getEvents (): array |
|
| 40 | 40 | { |
| 41 | 41 | return [ |
| 42 | 42 | new Event('topic', [$this->channel, $this->topic]), |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** @var string */ |
| 20 | 20 | public $user; |
| 21 | 21 | |
| 22 | - public function __construct(string $message) |
|
| 22 | + public function __construct (string $message) |
|
| 23 | 23 | { |
| 24 | 24 | parent::__construct($message); |
| 25 | 25 | $this->user = strstr($this->source, '!', true); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $this->message = $this->payload; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function getEvents(): array |
|
| 30 | + public function getEvents (): array |
|
| 31 | 31 | { |
| 32 | 32 | $events = []; |
| 33 | 33 | if ($this->target[0] === '#') { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | return $events; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function injectChannel(array $channels): void |
|
| 47 | + public function injectChannel (array $channels): void |
|
| 48 | 48 | { |
| 49 | 49 | if (array_key_exists($this->target, $channels)) { |
| 50 | 50 | $this->channel = $channels[$this->target]; |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class WelcomeMessage extends IrcMessage |
| 9 | 9 | { |
| 10 | - public function __construct(string $message) |
|
| 10 | + public function __construct (string $message) |
|
| 11 | 11 | { |
| 12 | 12 | parent::__construct($message); |
| 13 | 13 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * On welcome message, join the selected channels. |
| 17 | 17 | */ |
| 18 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 18 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 19 | 19 | { |
| 20 | 20 | if ($this->handled && !$force) { |
| 21 | 21 | return; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function getEvents(): array |
|
| 29 | + public function getEvents (): array |
|
| 30 | 30 | { |
| 31 | 31 | return [ |
| 32 | 32 | new Event('registered'), |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** @var string[] */ |
| 14 | 14 | public $names; |
| 15 | 15 | |
| 16 | - public function __construct(string $message) |
|
| 16 | + public function __construct (string $message) |
|
| 17 | 17 | { |
| 18 | 18 | parent::__construct($message); |
| 19 | 19 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | $this->names = explode(' ', $this->payload); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function handle(IrcClient $client, bool $force = false): void |
|
| 24 | + public function handle (IrcClient $client, bool $force = false): void |
|
| 25 | 25 | { |
| 26 | 26 | if ($this->handled && !$force) { |
| 27 | 27 | return; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function getEvents(): array |
|
| 35 | + public function getEvents (): array |
|
| 36 | 36 | { |
| 37 | 37 | return [ |
| 38 | 38 | new Event('names', [$this->channel, $this->names]), |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @param string $server The server address to connect to including the port: `address:port`. |
| 31 | 31 | * @param ClientOptions $options An object depicting options for this connection. |
| 32 | 32 | */ |
| 33 | - public function __construct(string $server, ?ClientOptions $options = null) |
|
| 33 | + public function __construct (string $server, ?ClientOptions $options = null) |
|
| 34 | 34 | { |
| 35 | 35 | $options = $options ?? new ClientOptions(); |
| 36 | 36 | $this->connection = new IrcConnection($server, $options->connectionOptions()); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @param IrcUser|string $user The user information. |
| 54 | 54 | */ |
| 55 | - public function setUser($user): void |
|
| 55 | + public function setUser ($user): void |
|
| 56 | 56 | { |
| 57 | 57 | if (is_string($user)) { |
| 58 | 58 | $user = new IrcUser($user); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * |
| 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('A nickname must be set before connecting to an irc server.'); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $this->isAuthenticated = false; |
| 84 | - $this->connection->onData(function ($msg) { |
|
| 84 | + $this->connection->onData(function($msg) { |
|
| 85 | 85 | $this->handleIrcMessage($msg); |
| 86 | 86 | }); |
| 87 | 87 | $this->connection->open(); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * Close the current connection, if any. |
| 92 | 92 | */ |
| 93 | - public function disconnect(): void |
|
| 93 | + public function disconnect (): void |
|
| 94 | 94 | { |
| 95 | 95 | $this->connection->close(); |
| 96 | 96 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $event The event to register to. |
| 102 | 102 | * @param callable $callback The callback to be execute when the event is emitted. |
| 103 | 103 | */ |
| 104 | - public function on(string $event, callable $callback): void |
|
| 104 | + public function on (string $event, callable $callback): void |
|
| 105 | 105 | { |
| 106 | 106 | $this->messageEventHandlers->addHandler($event, $callback); |
| 107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * |
| 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 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param string $target The channel or user to message. |
| 124 | 124 | * @param string $message The message to send. |
| 125 | 125 | */ |
| 126 | - public function say(string $target, string $message): void |
|
| 126 | + public function say (string $target, string $message): void |
|
| 127 | 127 | { |
| 128 | 128 | foreach (explode("\n", $message) as $msg) { |
| 129 | 129 | $this->send("PRIVMSG $target :" . trim($msg)); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @param string $channel The name of the channel to join. |
| 137 | 137 | */ |
| 138 | - public function join(string $channel): void |
|
| 138 | + public function join (string $channel): void |
|
| 139 | 139 | { |
| 140 | 140 | $channel = $this->channelName($channel); |
| 141 | 141 | $this->send("JOIN $channel"); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @param string $channel The name of the channel to leave. |
| 149 | 149 | */ |
| 150 | - public function part(string $channel): void |
|
| 150 | + public function part (string $channel): void |
|
| 151 | 151 | { |
| 152 | 152 | $channel = $this->channelName($channel); |
| 153 | 153 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @return IrcChannel |
| 166 | 166 | */ |
| 167 | - public function getChannel(string $channel): IrcChannel |
|
| 167 | + public function getChannel (string $channel): IrcChannel |
|
| 168 | 168 | { |
| 169 | 169 | $channel = $this->channelName($channel); |
| 170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return IrcChannel[] |
| 182 | 182 | */ |
| 183 | - public function getChannels(): array |
|
| 183 | + public function getChannels (): array |
|
| 184 | 184 | { |
| 185 | 185 | return $this->channels; |
| 186 | 186 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @param IrcMessage $message The message object for the received line. |
| 192 | 192 | */ |
| 193 | - private function handleIrcMessage(IrcMessage $message): void |
|
| 193 | + private function handleIrcMessage (IrcMessage $message): void |
|
| 194 | 194 | { |
| 195 | 195 | $message->injectChannel($this->channels); |
| 196 | 196 | $message->handle($this); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return string The formatted name. |
| 215 | 215 | */ |
| 216 | - private function channelName(string $channel): string |
|
| 216 | + private function channelName (string $channel): string |
|
| 217 | 217 | { |
| 218 | 218 | if ($channel[0] !== '#') { |
| 219 | 219 | $channel = "#$channel"; |