Skip to content

Commit

Permalink
Add sanitize method
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostzero committed Dec 21, 2020
1 parent dbc4def commit 5da9b0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 3 additions & 12 deletions src/Traits/Irc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand All @@ -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;
}
}

0 comments on commit 5da9b0a

Please sign in to comment.