| Conditions | 10 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 77 | protected function _users() |
||
| 78 | { |
||
| 79 | if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) { |
||
| 80 | if (strlen($strBuf) > 0) { |
||
| 81 | $lines = preg_split('/\n/', $strBuf); |
||
| 82 | $this->sys->setUsers(count($lines)); |
||
| 83 | } |
||
| 84 | } elseif (CommonFunctions::executeProgram('uptime', '', $buf, PSI_DEBUG) && preg_match("/,\s+(\d+)\s+user[s]?,/", $buf, $ar_buf)) { |
||
| 85 | //} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/,\s+(\d+)\s+user[s]?,\s+load average[s]?:\s+(.*),\s+(.*),\s+(.*)$/", $buf, $ar_buf)) { |
||
| 86 | $this->sys->setUsers($ar_buf[1]); |
||
| 87 | } else { |
||
| 88 | $processlist = glob('/proc/*/cmdline', GLOB_NOSORT); |
||
| 89 | if (($total = count($processlist)) > 0) { |
||
| 90 | $count = 0; |
||
| 91 | $buf = ""; |
||
| 92 | for ($i = 0; $i < $total; $i++) { |
||
| 93 | if (CommonFunctions::rfts($processlist[$i], $buf, 0, 4096, false)) { |
||
| 94 | $name = str_replace(chr(0), ' ', trim($buf)); |
||
| 95 | if (preg_match("/^-/", $name)) { |
||
| 96 | $count++; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | if ($count > 0) { |
||
| 101 | $this->sys->setUsers($count); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 150 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.