| Conditions | 25 |
| Paths | 5 |
| Total Lines | 46 |
| Code Lines | 38 |
| Lines | 46 |
| Ratio | 100 % |
| 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 |
||
| 60 | View Code Duplication | private function _network() |
|
| 61 | { |
||
| 62 | CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG); |
||
| 63 | CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG); |
||
| 64 | $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY); |
||
| 65 | $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY); |
||
| 66 | for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) { |
||
| 67 | $ar_buf_b = preg_split("/\s+/", $lines_b[$i]); |
||
| 68 | $ar_buf_n = preg_split("/\s+/", $lines_n[$i]); |
||
| 69 | if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) { |
||
| 70 | $dev = new NetDevice(); |
||
| 71 | $dev->setName($ar_buf_b[0]); |
||
| 72 | $dev->setTxBytes($ar_buf_b[4]); |
||
| 73 | $dev->setRxBytes($ar_buf_b[3]); |
||
| 74 | $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]); |
||
| 75 | $dev->setDrops($ar_buf_n[8]); |
||
| 76 | if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) { |
||
| 77 | $speedinfo = ""; |
||
| 78 | $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY); |
||
| 79 | foreach ($bufe2 as $buf2) { |
||
| 80 | if (preg_match('/^\s+lladdr\s+(\S+)/i', $buf2, $ar_buf2)) |
||
| 81 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1]))); |
||
| 82 | elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) |
||
| 83 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
||
| 84 | elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2) |
||
| 85 | || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2)) |
||
| 86 | && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) |
||
| 87 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
||
| 88 | elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) { |
||
| 89 | if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") { |
||
| 90 | $unit = "G"; |
||
| 91 | } else { |
||
| 92 | $unit = "M"; |
||
| 93 | } |
||
| 94 | if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3)) |
||
| 95 | $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]); |
||
| 96 | else |
||
| 97 | $speedinfo = $ar_buf2[1].$unit.'b/s'; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
||
| 101 | } |
||
| 102 | $this->sys->setNetDevices($dev); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 223 |
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.