| Conditions | 30 |
| Paths | 12 |
| Total Lines | 66 |
| Code Lines | 53 |
| Lines | 48 |
| Ratio | 72.73 % |
| 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 |
||
| 61 | private function _network() |
||
| 62 | { |
||
| 63 | $dev = null; |
||
| 64 | if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) { |
||
| 65 | $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY); |
||
| 66 | foreach ($lines as $line) { |
||
| 67 | $ar_buf = preg_split("/\s+/", $line); |
||
| 68 | if (!empty($ar_buf[0])) { |
||
| 69 | if (preg_match('/^<Link/i', $ar_buf[2])) { |
||
| 70 | $dev = new NetDevice(); |
||
| 71 | $dev->setName($ar_buf[0]); |
||
| 72 | if (strlen($ar_buf[3]) < 17) { /* no Address */ |
||
| 73 | View Code Duplication | if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/ |
|
| 74 | $dev->setTxBytes($ar_buf[9]); |
||
| 75 | $dev->setRxBytes($ar_buf[6]); |
||
| 76 | $dev->setErrors($ar_buf[4] + $ar_buf[8]); |
||
| 77 | $dev->setDrops($ar_buf[11] + $ar_buf[5]); |
||
| 78 | } else { |
||
| 79 | $dev->setTxBytes($ar_buf[8]); |
||
| 80 | $dev->setRxBytes($ar_buf[5]); |
||
| 81 | $dev->setErrors($ar_buf[4] + $ar_buf[7]); |
||
| 82 | $dev->setDrops($ar_buf[10]); |
||
| 83 | } |
||
| 84 | View Code Duplication | } else { |
|
| 85 | if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/ |
||
| 86 | $dev->setTxBytes($ar_buf[10]); |
||
| 87 | $dev->setRxBytes($ar_buf[7]); |
||
| 88 | $dev->setErrors($ar_buf[5] + $ar_buf[9]); |
||
| 89 | $dev->setDrops($ar_buf[12] + $ar_buf[6]); |
||
| 90 | } else { |
||
| 91 | $dev->setTxBytes($ar_buf[9]); |
||
| 92 | $dev->setRxBytes($ar_buf[6]); |
||
| 93 | $dev->setErrors($ar_buf[5] + $ar_buf[8]); |
||
| 94 | $dev->setDrops($ar_buf[11]); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | View Code Duplication | if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) { |
|
| 98 | $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY); |
||
| 99 | foreach ($bufe2 as $buf2) { |
||
| 100 | if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) |
||
| 101 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1]))); |
||
| 102 | elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) |
||
| 103 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
||
| 104 | elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2) |
||
| 105 | || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2)) |
||
| 106 | && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) |
||
| 107 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
||
| 108 | elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) { |
||
| 109 | if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") { |
||
| 110 | $unit = "G"; |
||
| 111 | } else { |
||
| 112 | $unit = "M"; |
||
| 113 | } |
||
| 114 | if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3)) |
||
| 115 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1])); |
||
| 116 | else |
||
| 117 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s'); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | $this->sys->setNetDevices($dev); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 202 |
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.