| Conditions | 18 |
| Paths | 521 |
| Total Lines | 56 |
| Code Lines | 38 |
| Lines | 24 |
| Ratio | 42.86 % |
| 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 |
||
| 74 | public function execute() |
||
| 75 | { |
||
| 76 | if (empty($this->_filecontent)) { |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | $group = ""; |
||
| 80 | foreach ($this->_filecontent as $block) { |
||
| 81 | if (preg_match('/^(NOTICE: )|(ERROR: )/m', $block)) { |
||
| 82 | $group = ""; |
||
| 83 | $lines = preg_split("/\r?\n/", $block, -1, PREG_SPLIT_NO_EMPTY); |
||
| 84 | foreach ($lines as $line) { |
||
| 85 | if (preg_match('/^NOTICE: added\s+\/dev\/(.+)\s+to RAID set\s+\"(.+)\"/', $line, $partition)) { |
||
| 86 | $this->_result['devices'][$partition[2]]['partitions'][$partition[1]]['status'] = "ok"; |
||
| 87 | } elseif (preg_match('/^ERROR: .* device\s+\/dev\/(.+)\s+(.+)\s+in RAID set\s+\"(.+)\"/', $line, $partition)) { |
||
| 88 | if ($partition[2]=="broken") { |
||
| 89 | $this->_result['devices'][$partition[3]]['partitions'][$partition[1]]['status'] = 'F'; |
||
| 90 | View Code Duplication | } else { |
|
| 91 | $this->_result['devices'][$partition[3]]['partitions'][$partition[1]]['status'] = 'W'; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } else { |
||
| 96 | if (preg_match('/^Group superset\s+(.+)/m', $block, $arrname)) { |
||
| 97 | $group = trim($arrname[1]); |
||
| 98 | } |
||
| 99 | if (preg_match('/^name\s*:\s*(.*)/m', $block, $arrname)) { |
||
| 100 | if ($group=="") { |
||
| 101 | $group = trim($arrname[1]); |
||
| 102 | } |
||
| 103 | $this->_result['devices'][$group]['name'] = $arrname[1]; |
||
| 104 | View Code Duplication | if (preg_match('/^size\s*:\s*(.*)/m', $block, $size)) { |
|
| 105 | $this->_result['devices'][$group]['size'] = trim($size[1]); |
||
| 106 | } |
||
| 107 | View Code Duplication | if (preg_match('/^stride\s*:\s*(.*)/m', $block, $stride)) { |
|
| 108 | $this->_result['devices'][$group]['stride'] = trim($stride[1]); |
||
| 109 | } |
||
| 110 | View Code Duplication | if (preg_match('/^type\s*:\s*(.*)/m', $block, $type)) { |
|
| 111 | $this->_result['devices'][$group]['type'] = trim($type[1]); |
||
| 112 | } |
||
| 113 | View Code Duplication | if (preg_match('/^status\s*:\s*(.*)/m', $block, $status)) { |
|
| 114 | $this->_result['devices'][$group]['status'] = trim($status[1]); |
||
| 115 | } |
||
| 116 | View Code Duplication | if (preg_match('/^subsets\s*:\s*(.*)/m', $block, $subsets)) { |
|
| 117 | $this->_result['devices'][$group]['subsets'] = trim($subsets[1]); |
||
| 118 | } |
||
| 119 | View Code Duplication | if (preg_match('/^devs\s*:\s*(.*)/m', $block, $devs)) { |
|
| 120 | $this->_result['devices'][$group]['devs'] = trim($devs[1]); |
||
| 121 | } |
||
| 122 | View Code Duplication | if (preg_match('/^spares\s*:\s*(.*)/m', $block, $spares)) { |
|
| 123 | $this->_result['devices'][$group]['spares'] = trim($spares[1]); |
||
| 124 | } |
||
| 125 | $group = ""; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 177 |
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.