| Conditions | 21 |
| Paths | 777 |
| Total Lines | 101 |
| Code Lines | 80 |
| Lines | 3 |
| Ratio | 2.97 % |
| 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 |
||
| 79 | public function execute() |
||
| 80 | { |
||
| 81 | if (empty($this->_filecontent)) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | // get the supported types |
||
| 85 | if (preg_match('/[a-zA-Z]* : (\[([a-z0-9])*\]([ \n]))+/', $this->_filecontent[0], $res)) { |
||
| 86 | $parts = preg_split("/ : /", $res[0]); |
||
| 87 | $parts = preg_split("/ /", $parts[1]); |
||
| 88 | $count = 0; |
||
| 89 | foreach ($parts as $types) { |
||
| 90 | if (trim($types) != "") { |
||
| 91 | $this->_result['supported_types'][$count++] = substr(trim($types), 1, -1); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | // get disks |
||
| 96 | if (preg_match("/^read_ahead/", $this->_filecontent[1])) { |
||
| 97 | $count = 2; |
||
| 98 | } else { |
||
| 99 | $count = 1; |
||
| 100 | } |
||
| 101 | $cnt_filecontent = count($this->_filecontent); |
||
| 102 | do { |
||
| 103 | $parts = preg_split("/ : /", $this->_filecontent[$count]); |
||
| 104 | $dev = trim($parts[0]); |
||
| 105 | if (count($parts) == 2) { |
||
| 106 | $details = preg_split('/ /', $parts[1]); |
||
| 107 | if (!strstr($details[0], 'inactive')) { |
||
| 108 | $this->_result['devices'][$dev]['level'] = $details[1]; |
||
| 109 | } else { |
||
| 110 | $this->_result['devices'][$dev]['level'] = "none"; |
||
| 111 | } |
||
| 112 | $this->_result['devices'][$dev]['status'] = $details[0]; |
||
| 113 | for ($i = 2, $cnt_details = count($details); $i < $cnt_details; $i++) { |
||
| 114 | preg_match('/(([a-z0-9])+)(\[([0-9]+)\])(\([SF ]\))?/', trim($details[$i]), $partition); |
||
| 115 | if (count($partition) == 5 || count($partition) == 6) { |
||
| 116 | $this->_result['devices'][$dev]['partitions'][$partition[1]]['raid_index'] = substr(trim($partition[3]), 1, -1); |
||
| 117 | if (isset($partition[5])) { |
||
| 118 | $search = array("(", ")"); |
||
| 119 | $replace = array("", ""); |
||
| 120 | $this->_result['devices'][$dev]['partitions'][$partition[1]]['status'] = str_replace($search, $replace, trim($partition[5])); |
||
| 121 | View Code Duplication | } else { |
|
| 122 | $this->_result['devices'][$dev]['partitions'][$partition[1]]['status'] = "ok"; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $count++; |
||
| 127 | $optionline = $this->_filecontent[$count - 1].$this->_filecontent[$count]; |
||
| 128 | if (preg_match('/([^\sk]*)k chunk/', $optionline, $chunksize)) { |
||
| 129 | $this->_result['devices'][$dev]['chunk_size'] = $chunksize[1]; |
||
| 130 | } else { |
||
| 131 | $this->_result['devices'][$dev]['chunk_size'] = -1; |
||
| 132 | } |
||
| 133 | if ($pos = strpos($optionline, "super non-persistent")) { |
||
| 134 | $this->_result['devices'][$dev]['pers_superblock'] = 0; |
||
| 135 | } else { |
||
| 136 | $this->_result['devices'][$dev]['pers_superblock'] = 1; |
||
| 137 | } |
||
| 138 | if ($pos = strpos($optionline, "algorithm")) { |
||
| 139 | $this->_result['devices'][$dev]['algorithm'] = trim(substr($optionline, $pos + 9, 2)); |
||
| 140 | } else { |
||
| 141 | $this->_result['devices'][$dev]['algorithm'] = -1; |
||
| 142 | } |
||
| 143 | if (preg_match('/(\[[0-9]?\/[0-9]\])/', $optionline, $res)) { |
||
| 144 | $slashpos = strpos($res[0], '/'); |
||
| 145 | $this->_result['devices'][$dev]['registered'] = substr($res[0], 1, $slashpos - 1); |
||
| 146 | $this->_result['devices'][$dev]['active'] = substr($res[0], $slashpos + 1, strlen($res[0]) - $slashpos - 2); |
||
| 147 | } else { |
||
| 148 | $this->_result['devices'][$dev]['registered'] = -1; |
||
| 149 | $this->_result['devices'][$dev]['active'] = -1; |
||
| 150 | } |
||
| 151 | if (preg_match(('/([a-z]+)( *)=( *)([0-9\.]+)%/'), $this->_filecontent[$count + 1], $res) || (preg_match(('/([a-z]+)( *)=( *)([0-9\.]+)/'), $optionline, $res))) { |
||
| 152 | list($this->_result['devices'][$dev]['action']['name'], $this->_result['devices'][$dev]['action']['percent']) = preg_split("/=/", str_replace("%", "", $res[0])); |
||
| 153 | if (preg_match(('/([a-z]*=[0-9\.]+[a-z]+)/'), $this->_filecontent[$count + 1], $res)) { |
||
| 154 | $time = preg_split("/=/", $res[0]); |
||
| 155 | list($this->_result['devices'][$dev]['action']['finish_time'], $this->_result['devices'][$dev]['action']['finish_unit']) = sscanf($time[1], '%f%s'); |
||
| 156 | } else { |
||
| 157 | $this->_result['devices'][$dev]['action']['finish_time'] = -1; |
||
| 158 | $this->_result['devices'][$dev]['action']['finish_unit'] = -1; |
||
| 159 | } |
||
| 160 | } else { |
||
| 161 | $this->_result['devices'][$dev]['action']['name'] = -1; |
||
| 162 | $this->_result['devices'][$dev]['action']['percent'] = -1; |
||
| 163 | $this->_result['devices'][$dev]['action']['finish_time'] = -1; |
||
| 164 | $this->_result['devices'][$dev]['action']['finish_unit'] = -1; |
||
| 165 | } |
||
| 166 | } else { |
||
| 167 | $count++; |
||
| 168 | } |
||
| 169 | } while ($cnt_filecontent > $count); |
||
| 170 | $lastline = $this->_filecontent[$cnt_filecontent - 2]; |
||
| 171 | if (strpos($lastline, "unused devices") !== false) { |
||
| 172 | $parts = preg_split("/:/", $lastline); |
||
| 173 | $search = array("<", ">"); |
||
| 174 | $replace = array("", ""); |
||
| 175 | $this->_result['unused_devs'] = trim(str_replace($search, $replace, $parts[1])); |
||
| 176 | } else { |
||
| 177 | $this->_result['unused_devs'] = -1; |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 237 |
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.