| Conditions | 16 |
| Paths | 1537 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 52 | private function _info() |
||
| 53 | { |
||
| 54 | foreach ($this->_output as $ups) { |
||
| 55 | |||
| 56 | $dev = new UPSDevice(); |
||
| 57 | |||
| 58 | // General info |
||
| 59 | $dev->setName("EVER"); |
||
| 60 | $dev->setMode("PowerSoftPlus"); |
||
| 61 | $maxpwr = 0; |
||
| 62 | $load = null; |
||
| 63 | if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 64 | $dev->setModel(trim($data[1])); |
||
| 65 | if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) { |
||
| 66 | $maxpwr=$number[1]*0.65; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 70 | $dev->setStatus(trim($data[1])); |
||
| 71 | } |
||
| 72 | if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) { |
||
| 73 | $load = trim($data[1]); |
||
| 74 | } |
||
| 75 | //wrong Output load issue |
||
| 76 | if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) { |
||
| 77 | $load = 100.0*trim($data[1])/$maxpwr; |
||
| 78 | } |
||
| 79 | if ($load != null) { |
||
| 80 | $dev->setLoad($load); |
||
| 81 | } |
||
| 82 | // Battery |
||
| 83 | if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) { |
||
| 84 | $dev->setBatteryVoltage(trim($data[1])); |
||
| 85 | } |
||
| 86 | if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 87 | if (preg_match('/^At full capacity$/', trim($data[1]))) { |
||
| 88 | $dev->setBatterCharge(100); |
||
| 89 | } elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) { |
||
| 90 | $dev->setBatterCharge(0); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | // Line |
||
| 94 | if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) { |
||
| 95 | $dev->setLineVoltage(trim($data[1])); |
||
| 96 | } |
||
| 97 | if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) { |
||
| 98 | $dev->setLineFrequency(trim($data[1])); |
||
| 99 | } |
||
| 100 | $this->upsinfo->setUpsDevices($dev); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 116 |
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.