From 5da9b0afdbf662c907408a8e67aef9f558ebb3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Preu=C3=9F?= Date: Mon, 21 Dec 2020 19:32:14 +0100 Subject: [PATCH] Add sanitize method --- src/Channel.php | 9 +++++++++ src/Traits/Irc.php | 15 +++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Channel.php b/src/Channel.php index 7fe5bba..ab32cce 100644 --- a/src/Channel.php +++ b/src/Channel.php @@ -52,4 +52,13 @@ public function __toString() { return $this->getName(); } + + public static function sanitize(string $channel): string + { + if ($channel[0] !== '#') { + $channel = "#$channel"; + } + + return strtolower($channel); + } } diff --git a/src/Traits/Irc.php b/src/Traits/Irc.php index dde6535..42aee81 100644 --- a/src/Traits/Irc.php +++ b/src/Traits/Irc.php @@ -12,20 +12,20 @@ trait Irc { public function say(string $channel, string $message): void { - $channel = $this->channelName($channel); + $channel = Channel::sanitize($channel); $this->write("PRIVMSG {$channel} :{$message}"); } public function join(string $channel): void { - $channel = $this->channelName($channel); + $channel = Channel::sanitize($channel); $this->channels[$channel] = new Channel($channel, true); $this->write("JOIN {$channel}"); } public function part(string $channel): void { - $channel = $this->channelName($channel); + $channel = Channel::sanitize($channel); unset($this->channels[$channel]); $this->write("PART {$channel}"); } @@ -39,13 +39,4 @@ public function getChannel(string $channel): Channel { return $this->channels[$channel]; } - - private function channelName(string $channel): string - { - if ($channel[0] !== '#') { - $channel = "#$channel"; - } - - return $channel; - } }