Skip to content

Commit

Permalink
Merge pull request #54 from WildPHP/fix/myinfo-5th-param
Browse files Browse the repository at this point in the history
MyInfo message now accepts only 5 parameters
  • Loading branch information
NanoSector authored Dec 27, 2020
2 parents a31db88 + 4ddf532 commit 46f19af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/RPL/MyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ public static function fromIncomingMessage(IrcMessageInterface $incomingMessage)
));
}

[$nickname, $server, $version, $userModes, $channelModes, $channelModesParam] = $incomingMessage->getArgs();
[
$nickname,
$server,
$version,
$userModes,
$channelModes,
$channelModesParam,
] = $incomingMessage->getArgs() + [5 => ''];

$object = new self();
$object->setNickname($nickname);
$object->setServer($server);
$object->setVersion($version);
$object->setUserModes(str_split($userModes));
$object->setChannelModes(str_split($channelModes));
$object->setChannelModesWithParameter(str_split($channelModesParam));
$object->setUserModes(array_filter(str_split($userModes)));
$object->setChannelModes(array_filter(str_split($channelModes)));
$object->setChannelModesWithParameter(array_filter(str_split($channelModesParam)));
$object->setTags($incomingMessage->getTags());

return $object;
Expand Down
16 changes: 16 additions & 0 deletions tests/MyInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ public function testFromIncomingMessage(): void
$this->assertEquals(['g', 'h', 'i'], $rpl_welcome->getChannelModesWithParameter());
}

public function testFromIncomingMessageWithFiveParameters(): void
{
$prefix = 'server';
$verb = '004';
$args = ['nickname', 'server', '1.0', 'abc', 'def'];
$incoming = new IrcMessage($prefix, $verb, $args);
$rpl_welcome = MyInfo::fromIncomingMessage($incoming);

$this->assertEquals('server', $rpl_welcome->getServer());
$this->assertEquals('nickname', $rpl_welcome->getNickname());
$this->assertEquals('1.0', $rpl_welcome->getVersion());
$this->assertEquals(['a', 'b', 'c'], $rpl_welcome->getUserModes());
$this->assertEquals(['d', 'e', 'f'], $rpl_welcome->getChannelModes());
$this->assertEquals([], $rpl_welcome->getChannelModesWithParameter());
}

public function testFromIncomingMessageThrowsException(): void
{
$prefix = ':server';
Expand Down

0 comments on commit 46f19af

Please sign in to comment.