| Conditions | 26 |
| Paths | 4010 |
| Total Lines | 68 |
| Code Lines | 47 |
| Lines | 29 |
| Ratio | 42.65 % |
| 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 |
||
| 70 | private function _filesystems() |
||
| 71 | { |
||
| 72 | if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG)) { |
||
| 73 | $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); |
||
| 74 | if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) { |
||
| 75 | $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY); |
||
| 76 | foreach ($mount as $mount_line) { |
||
| 77 | $mount_buf = preg_split('/\s+/', $mount_line); |
||
| 78 | if (count($mount_buf) == 6) { |
||
| 79 | $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2]; |
||
| 80 | if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3]; |
||
| 81 | $mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0]; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | foreach ($df as $df_line) { |
||
| 85 | if ((preg_match("/^(\/\S+)(\s+)(([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+))/", $df_line, $df_buf) |
||
| 86 | || preg_match("/^(\/[^\s\:]+)\:(\s+)(([0-9\.]+)([KMGT])(\s+total\,\s+)([0-9\.]+)([KMGT])(\s+used\,\s+)([0-9\.]+)([KMGT])(\s+available))/", $df_line, $df_buf)) |
||
| 87 | && !preg_match('/^\/mnt\/asec\/com\./', $df_buf[1])) { |
||
| 88 | $dev = new DiskDevice(); |
||
| 89 | if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[1]); |
||
| 90 | |||
| 91 | View Code Duplication | if ($df_buf[5] == 'K') $dev->setTotal($df_buf[4] * 1024); |
|
| 92 | elseif ($df_buf[5] == 'M') $dev->setTotal($df_buf[4] * 1024*1024); |
||
| 93 | elseif ($df_buf[5] == 'G') $dev->setTotal($df_buf[4] * 1024*1024*1024); |
||
| 94 | elseif ($df_buf[5] == 'T') $dev->setTotal($df_buf[4] * 1024*1024*1024*1024); |
||
| 95 | |||
| 96 | View Code Duplication | if ($df_buf[8] == 'K') $dev->setUsed($df_buf[7] * 1024); |
|
| 97 | elseif ($df_buf[8] == 'M') $dev->setUsed($df_buf[7] * 1024*1024); |
||
| 98 | elseif ($df_buf[8] == 'G') $dev->setUsed($df_buf[7] * 1024*1024*1024); |
||
| 99 | elseif ($df_buf[8] == 'T') $dev->setUsed($df_buf[7] * 1024*1024*1024*1024); |
||
| 100 | |||
| 101 | View Code Duplication | if ($df_buf[11] == 'K') $dev->setFree($df_buf[10] * 1024); |
|
| 102 | elseif ($df_buf[11] == 'M') $dev->setFree($df_buf[10] * 1024*1024); |
||
| 103 | elseif ($df_buf[11] == 'G') $dev->setFree($df_buf[10] * 1024*1024*1024); |
||
| 104 | elseif ($df_buf[11] == 'T') $dev->setFree($df_buf[10] * 1024*1024*1024*1024); |
||
| 105 | |||
| 106 | if (isset($mount_parm[$df_buf[1]])) { |
||
| 107 | $dev->setFsType($mount_parm[$df_buf[1]]['fstype']); |
||
| 108 | $dev->setName($mount_parm[$df_buf[1]]['mountdev']); |
||
| 109 | |||
| 110 | if (PSI_SHOW_MOUNT_OPTION) { |
||
| 111 | if (PSI_SHOW_MOUNT_CREDENTIALS) { |
||
| 112 | $dev->setOptions($mount_parm[$df_buf[1]]['options']); |
||
| 113 | View Code Duplication | } else { |
|
| 114 | $mpo=$mount_parm[$df_buf[1]]['options']; |
||
| 115 | |||
| 116 | $mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo); |
||
| 117 | $mpo=preg_replace('/,guest,/i', ',', $mpo); |
||
| 118 | |||
| 119 | $mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo); |
||
| 120 | $mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo); |
||
| 121 | |||
| 122 | $mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo); |
||
| 123 | $mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo); |
||
| 124 | |||
| 125 | $mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo); |
||
| 126 | $mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo); |
||
| 127 | |||
| 128 | $dev->setOptions($mpo); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | $this->sys->setDiskDevices($dev); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 254 |
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.