| Conditions | 19 |
| Paths | > 20000 |
| Total Lines | 66 |
| Code Lines | 40 |
| 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 |
||
| 67 | private function _info() |
||
| 68 | { |
||
| 69 | foreach ($this->_output as $ups) { |
||
| 70 | |||
| 71 | $dev = new UPSDevice(); |
||
| 72 | |||
| 73 | // General info |
||
| 74 | if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 75 | $dev->setName(trim($data[1])); |
||
| 76 | } |
||
| 77 | if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 78 | $model=trim($data[1]); |
||
| 79 | if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 80 | $dev->setModel($model.' ('.trim($data[1]).')'); |
||
| 81 | } else { |
||
| 82 | $dev->setModel($model); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 86 | $dev->setMode(trim($data[1])); |
||
| 87 | } |
||
| 88 | if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 89 | $dev->setStartTime(trim($data[1])); |
||
| 90 | } |
||
| 91 | if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 92 | $dev->setStatus(trim($data[1])); |
||
| 93 | } |
||
| 94 | if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 95 | $dev->setTemperatur(trim($data[1])); |
||
| 96 | } |
||
| 97 | // Outages |
||
| 98 | if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 99 | $dev->setOutages(trim($data[1])); |
||
| 100 | } |
||
| 101 | if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 102 | $dev->setLastOutage(trim($data[1])); |
||
| 103 | } |
||
| 104 | if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 105 | $dev->setLastOutageFinish(trim($data[1])); |
||
| 106 | } |
||
| 107 | // Line |
||
| 108 | if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 109 | $dev->setLineVoltage(trim($data[1])); |
||
| 110 | } |
||
| 111 | if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 112 | $dev->setLineFrequency(trim($data[1])); |
||
| 113 | } |
||
| 114 | if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 115 | $dev->setLoad(trim($data[1])); |
||
| 116 | } |
||
| 117 | // Battery |
||
| 118 | if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) { |
||
| 119 | $dev->setBatteryDate(trim($data[1])); |
||
| 120 | } |
||
| 121 | if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 122 | $dev->setBatteryVoltage(trim($data[1])); |
||
| 123 | } |
||
| 124 | if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 125 | $dev->setBatterCharge(trim($data[1])); |
||
| 126 | } |
||
| 127 | if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) { |
||
| 128 | $dev->setTimeLeft(trim($data[1])); |
||
| 129 | } |
||
| 130 | $this->upsinfo->setUpsDevices($dev); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 146 |
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.