| Conditions | 20 |
| Paths | 65 |
| Total Lines | 74 |
| Code Lines | 58 |
| Lines | 40 |
| Ratio | 54.05 % |
| 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 |
||
| 194 | public function xml() |
||
| 195 | { |
||
| 196 | if (empty($this->_lines)) |
||
| 197 | return $this->xml->getSimpleXmlElement(); |
||
| 198 | |||
| 199 | $arrBuff = $this->temperatures(); |
||
| 200 | View Code Duplication | if (sizeof($arrBuff) > 0) { |
|
| 201 | $temp = $this->xml->addChild("Temperatures"); |
||
| 202 | foreach ($arrBuff as $arrValue) { |
||
| 203 | $item = $temp->addChild('Item'); |
||
| 204 | $item->addAttribute('Label', $arrValue['label']); |
||
| 205 | $item->addAttribute('Value', $arrValue['value']); |
||
| 206 | $item->addAttribute('State', $arrValue['state']); |
||
| 207 | if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['Max']); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | $arrBuff = $this->voltages(); |
||
| 211 | if (sizeof($arrBuff) > 0) { |
||
| 212 | $volt = $this->xml->addChild('Voltages'); |
||
| 213 | foreach ($arrBuff as $arrValue) { |
||
| 214 | $item = $volt->addChild('Item'); |
||
| 215 | $item->addAttribute('Label', $arrValue['label']); |
||
| 216 | $item->addAttribute('Value', $arrValue['value']); |
||
| 217 | $item->addAttribute('State', $arrValue['state']); |
||
| 218 | if (isset($arrValue['Min'])) $item->addAttribute('Min', $arrValue['min']); |
||
| 219 | if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | $arrBuff = $this->fans(); |
||
| 223 | View Code Duplication | if (sizeof($arrBuff) > 0) { |
|
| 224 | $fan = $this->xml->addChild('Fans'); |
||
| 225 | foreach ($arrBuff as $arrValue) { |
||
| 226 | $item = $fan->addChild('Item'); |
||
| 227 | $item->addAttribute('Label', $arrValue['label']); |
||
| 228 | $item->addAttribute('Value', $arrValue['value']); |
||
| 229 | $item->addAttribute('State', $arrValue['state']); |
||
| 230 | if (isset($arrValue['Min'])) $item->addAttribute('Min', $arrValue['min']); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | $arrBuff = $this->powers(); |
||
| 234 | View Code Duplication | if (sizeof($arrBuff) > 0) { |
|
| 235 | $misc = $this->xml->addChild('Powers'); |
||
| 236 | foreach ($arrBuff as $arrValue) { |
||
| 237 | $item = $misc->addChild('Item'); |
||
| 238 | $item->addAttribute('Label', $arrValue['label']); |
||
| 239 | $item->addAttribute('Value', $arrValue['value']); |
||
| 240 | $item->addAttribute('State', $arrValue['state']); |
||
| 241 | if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | $arrBuff = $this->currents(); |
||
| 245 | View Code Duplication | if (sizeof($arrBuff) > 0) { |
|
| 246 | $misc = $this->xml->addChild('Currents'); |
||
| 247 | foreach ($arrBuff as $arrValue) { |
||
| 248 | $item = $misc->addChild('Item'); |
||
| 249 | $item->addAttribute('Label', $arrValue['label']); |
||
| 250 | $item->addAttribute('Value', $arrValue['value']); |
||
| 251 | $item->addAttribute('State', $arrValue['state']); |
||
| 252 | if (isset($arrValue['Max'])) $item->addAttribute('Max', $arrValue['max']); |
||
| 253 | } |
||
| 254 | } |
||
| 255 | $arrBuff = $this->misc(); |
||
| 256 | if (sizeof($arrBuff) > 0) { |
||
| 257 | $misc = $this->xml->addChild('Misc'); |
||
| 258 | foreach ($arrBuff as $arrValue) { |
||
| 259 | $item = $misc->addChild('Item'); |
||
| 260 | $item->addAttribute('Label', $arrValue['label']); |
||
| 261 | $item->addAttribute('Value', $arrValue['value']); |
||
| 262 | $item->addAttribute('State', $arrValue['state']); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | return $this->xml->getSimpleXmlElement(); |
||
| 267 | } |
||
| 268 | |||
| 270 |
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.