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