Conditions | 15 |
Paths | 3074 |
Total Lines | 54 |
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 |
||
76 | private function _info() |
||
77 | { |
||
78 | if (! empty($this->_output)) { |
||
79 | foreach ($this->_output as $name=>$value) { |
||
80 | $temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY); |
||
81 | $ups_data = array(); |
||
82 | foreach ($temp as $value) { |
||
83 | $line = preg_split('/: /', $value, 2); |
||
84 | $ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : ''; |
||
85 | } |
||
86 | $dev = new UPSDevice(); |
||
87 | //General |
||
88 | $dev->setName($name); |
||
89 | if (isset($ups_data['ups.model'])) { |
||
90 | $dev->setModel($ups_data['ups.model']); |
||
91 | } |
||
92 | if (isset($ups_data['driver.name'])) { |
||
93 | $dev->setMode($ups_data['driver.name']); |
||
94 | } |
||
95 | if (isset($ups_data['ups.status'])) { |
||
96 | $dev->setStatus($ups_data['ups.status']); |
||
97 | } |
||
98 | |||
99 | //Line |
||
100 | if (isset($ups_data['input.voltage'])) { |
||
101 | $dev->setLineVoltage($ups_data['input.voltage']); |
||
102 | } |
||
103 | if (isset($ups_data['input.frequency'])) { |
||
104 | $dev->setLineFrequency($ups_data['input.frequency']); |
||
105 | } |
||
106 | if (isset($ups_data['ups.load'])) { |
||
107 | $dev->setLoad($ups_data['ups.load']); |
||
108 | } |
||
109 | |||
110 | //Battery |
||
111 | if (isset($ups_data['battery.voltage'])) { |
||
112 | $dev->setBatteryVoltage($ups_data['battery.voltage']); |
||
113 | } |
||
114 | if (isset($ups_data['battery.charge'])) { |
||
115 | $dev->setBatterCharge($ups_data['battery.charge']); |
||
116 | } |
||
117 | if (isset($ups_data['battery.runtime'])) { |
||
118 | $dev->setTimeLeft(round($ups_data['battery.runtime']/60, 2)); |
||
119 | } |
||
120 | |||
121 | //Temperature |
||
122 | if (isset($ups_data['ups.temperature'])) { |
||
123 | $dev->setTemperatur($ups_data['ups.temperature']); |
||
124 | } |
||
125 | |||
126 | $this->upsinfo->setUpsDevices($dev); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
143 |
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.