| Conditions | 10 |
| Paths | 25 |
| Total Lines | 34 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 32 | public function onRead() { |
||
| 33 | while (!is_null($line = $this->readline())) { |
||
| 34 | $finish = |
||
| 35 | (strpos($line, $s = "\xff\xf4\xff\xfd\x06") !== FALSE) |
||
| 36 | || (strpos($line, $s = "\xff\xec") !== FALSE) |
||
| 37 | || (strpos($line, $s = "\x03") !== FALSE) |
||
| 38 | || (strpos($line, $s = "\x04") !== FALSE); |
||
| 39 | |||
| 40 | $e = explode(' ', rtrim($line, "\r\n"), 2); |
||
| 41 | |||
| 42 | $cmd = trim($e[0]); |
||
| 43 | |||
| 44 | if ($cmd === 'ping') { |
||
| 45 | $this->writeln('pong'); |
||
| 46 | } |
||
| 47 | elseif ( |
||
| 48 | ($cmd === 'exit') |
||
| 49 | || ($cmd === 'quit') |
||
| 50 | ) { |
||
| 51 | $this->writeln('Quit'); |
||
| 52 | $this->finish(); |
||
| 53 | } |
||
| 54 | else { |
||
| 55 | $this->writeln('Unknown command "' . $cmd . '"'); |
||
| 56 | } |
||
| 57 | |||
| 58 | if ( |
||
| 59 | (strlen($line) > 1024) |
||
| 60 | || $finish |
||
| 61 | ) { |
||
| 62 | $this->finish(); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 75 |