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; - } }