| Conditions | 7 |
| Paths | 2 |
| Total Lines | 53 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 96 | private function startBot(OutputInterface $output, IRCServer $ircServer) |
||
| 97 | { |
||
| 98 | $connection = new Connection(); |
||
| 99 | |||
| 100 | $connection |
||
| 101 | ->setServerHostname($ircServer->getHost()) |
||
| 102 | ->setNickname('xdaysaysay') |
||
| 103 | ->setUsername('xdaysaysay') |
||
| 104 | ->setHostname('xdaysaysay') |
||
| 105 | ->setRealname('xdaysaysay') |
||
| 106 | ->setOption('write', new WriteStream()); |
||
| 107 | if ($ircServer->getPortSsl()) { |
||
| 108 | $connection->setOption('transport', 'ssl'); |
||
| 109 | $connection->setServerPort($ircServer->getPortSsl()); |
||
| 110 | } else { |
||
| 111 | $connection->setServerPort($ircServer->getPort()); |
||
| 112 | } |
||
| 113 | |||
| 114 | $output->writeln('Connection to '.$connection->getServerHostname()); |
||
| 115 | |||
| 116 | $client = new Client(); |
||
| 117 | |||
| 118 | $client->on('irc.received', function ($message, WriteStream $write, Connection $connection, LoggerInterface $logger) { |
||
| 119 | if ($message['command'] !== 'JOIN') { |
||
| 120 | return; |
||
| 121 | } |
||
| 122 | $channel = $message['params']['channels']; |
||
| 123 | $nick = $message['nick']; |
||
| 124 | $write->ircPrivmsg($channel, 'Welcome '.$nick.'!'); |
||
| 125 | }); |
||
| 126 | |||
| 127 | $client->on('connect.after.each', function (Connection $connection, WriteStream $write) use ($output, $client) { |
||
| 128 | $output->writeln('Connected to '.$connection->getServerHostname()); |
||
| 129 | if ($write) { |
||
| 130 | /** @var Team $team */ |
||
| 131 | foreach (self::$ircServers[$connection->getServerHostname()]['teams'] as $team) { |
||
| 132 | $client->addTimer(15, function() use($write, $team) { |
||
| 133 | $join = $write->ircJoin($team->getChanNameStaff(), $team->getChanNameStaffPassword() ? : null); |
||
| 134 | dump($join); |
||
| 135 | $join = $write->ircJoin($team->getChanName(), $team->getChanNamePassword() ? : null); |
||
| 136 | dump($join); |
||
| 137 | }); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | }); |
||
| 141 | |||
| 142 | $client->on('connect.error', function (\Exception $exception, ConnectionInterface $connection, LoggerInterface $logger) { |
||
| 143 | dump('connect.error'); |
||
| 144 | $logger->debug('Connection to '.$connection->getServerHostname().' lost: '.$exception->getMessage()); |
||
| 145 | }); |
||
| 146 | // $client->setTickInterval() |
||
| 147 | $client->run($connection); |
||
| 148 | } |
||
| 149 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.