| Conditions | 11 |
| Paths | 19 |
| Total Lines | 40 |
| Code Lines | 30 |
| Lines | 16 |
| Ratio | 40 % |
| 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 |
||
| 136 | public function xml() |
||
| 137 | { |
||
| 138 | if (empty($this->_result)) { |
||
| 139 | return $this->xml->getSimpleXmlElement(); |
||
| 140 | } |
||
| 141 | $hideRaids = array(); |
||
| 142 | View Code Duplication | if (defined('PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES') && is_string(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES)) { |
|
| 143 | if (preg_match(ARRAY_EXP, PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES)) { |
||
| 144 | $hideRaids = eval(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES); |
||
| 145 | } else { |
||
| 146 | $hideRaids = array(PSI_PLUGIN_DMRAID_HIDE_RAID_DEVICES); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | foreach ($this->_result['devices'] as $key=>$device) { |
||
| 150 | if (!in_array($key, $hideRaids, true)) { |
||
| 151 | $dev = $this->xml->addChild("Raid"); |
||
| 152 | $dev->addAttribute("Device_Name", $key); |
||
| 153 | $dev->addAttribute("Type", $device["type"]); |
||
| 154 | $dev->addAttribute("Disk_Status", $device["status"]); |
||
| 155 | $dev->addAttribute("Name", $device["name"]); |
||
| 156 | $dev->addAttribute("Size", $device["size"]); |
||
| 157 | $dev->addAttribute("Stride", $device["stride"]); |
||
| 158 | $dev->addAttribute("Subsets", $device["subsets"]); |
||
| 159 | $dev->addAttribute("Devs", $device["devs"]); |
||
| 160 | $dev->addAttribute("Spares", $device["spares"]); |
||
| 161 | $disks = $dev->addChild("Disks"); |
||
| 162 | View Code Duplication | if (isset($device['partitions']) && sizeof($device['partitions']>0)) foreach ($device['partitions'] as $diskkey=>$disk) { |
|
| 163 | $disktemp = $disks->addChild("Disk"); |
||
| 164 | $disktemp->addAttribute("Name", $diskkey); |
||
| 165 | if ($device["status"]=='ok') { |
||
| 166 | $disktemp->addAttribute("Status", $disk['status']); |
||
| 167 | } else { |
||
| 168 | $disktemp->addAttribute("Status", 'W'); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | return $this->xml->getSimpleXmlElement(); |
||
| 175 | } |
||
| 176 | } |
||
| 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.