Conditions | 21 |
Paths | 1024 |
Total Lines | 152 |
Code Lines | 116 |
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 |
||
96 | public function pollOS() |
||
97 | { |
||
98 | // Migrated to Wireless Sensor |
||
99 | $fec = snmp_get_multi_oid($this->getDeviceArray(), ['fecInErrorsCount.0', 'fecOutErrorsCount.0', 'fecCRCError.0'], '-OQUs', 'WHISP-BOX-MIBV2-MIB'); |
||
100 | if (is_numeric($fec['fecInErrorsCount.0']) && is_numeric($fec['fecOutErrorsCount.0'])) { |
||
101 | $rrd_def = RrdDefinition::make() |
||
102 | ->addDataset('fecInErrorsCount', 'GAUGE', 0, 100000) |
||
103 | ->addDataset('fecOutErrorsCount', 'GAUGE', 0, 100000); |
||
104 | |||
105 | $fields = [ |
||
106 | 'fecInErrorsCount' => $fec['fecInErrorsCount.0'], |
||
107 | 'fecOutErrorsCount' => $fec['fecOutErrorsCount.0'], |
||
108 | ]; |
||
109 | $tags = compact('rrd_def'); |
||
110 | data_update($this->getDeviceArray(), 'canopy-generic-errorCount', $tags, $fields); |
||
111 | $this->enableGraph('canopy_generic_errorCount'); |
||
112 | } |
||
113 | |||
114 | // Migrated to Wireless Sensor |
||
115 | if (is_numeric($fec['fecCRCError.0'])) { |
||
116 | $rrd_def = RrdDefinition::make()->addDataset('crcErrors', 'GAUGE', 0, 100000); |
||
117 | $fields = [ |
||
118 | 'crcErrors' => $fec['fecCRCError.0'], |
||
119 | ]; |
||
120 | $tags = compact('rrd_def'); |
||
121 | data_update($this->getDeviceArray(), 'canopy-generic-crcErrors', $tags, $fields); |
||
122 | $this->enableGraph('canopy_generic_crcErrors'); |
||
123 | } |
||
124 | |||
125 | $jitter = snmp_get($this->getDeviceArray(), 'jitter.0', '-Ovqn', 'WHISP-SM-MIB'); |
||
126 | if (is_numeric($jitter)) { |
||
127 | $rrd_def = RrdDefinition::make()->addDataset('jitter', 'GAUGE', 0, 20); |
||
128 | $fields = [ |
||
129 | 'jitter' => $jitter, |
||
130 | ]; |
||
131 | $tags = compact('rrd_def'); |
||
132 | data_update($this->getDeviceArray(), 'canopy-generic-jitter', $tags, $fields); |
||
133 | $this->enableGraph('canopy_generic_jitter'); |
||
134 | unset($rrd_def, $jitter); |
||
135 | } |
||
136 | |||
137 | $multi_get_array = snmp_get_multi($this->getDeviceArray(), ['regCount.0', 'regFailureCount.0'], '-OQU', 'WHISP-APS-MIB'); |
||
138 | d_echo($multi_get_array); |
||
139 | $registered = $multi_get_array[0]['WHISP-APS-MIB::regCount']; |
||
140 | $failed = $multi_get_array[0]['WHISP-APS-MIB::regFailureCount']; |
||
141 | |||
142 | if (is_numeric($registered) && is_numeric($failed)) { |
||
143 | $rrd_def = RrdDefinition::make() |
||
144 | ->addDataset('regCount', 'GAUGE', 0, 15000) |
||
145 | ->addDataset('failed', 'GAUGE', 0, 15000); |
||
146 | $fields = [ |
||
147 | 'regCount' => $registered, |
||
148 | 'failed' => $failed, |
||
149 | ]; |
||
150 | $tags = compact('rrd_def'); |
||
151 | data_update($this->getDeviceArray(), 'canopy-generic-regCount', $tags, $fields); |
||
152 | $this->enableGraph('canopy_generic_regCount'); |
||
153 | unset($rrd_def, $registered, $failed); |
||
154 | } |
||
155 | |||
156 | $visible = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.4.4.7.0', '-Ovqn', '')); |
||
157 | $tracked = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.4.4.8.0', '-Ovqn', '')); |
||
158 | if (is_numeric($visible) && is_numeric($tracked)) { |
||
159 | $rrd_def = RrdDefinition::make() |
||
160 | ->addDataset('visible', 'GAUGE', 0, 1000) |
||
161 | ->addDataset('tracked', 'GAUGE', 0, 1000); |
||
162 | $fields = [ |
||
163 | 'visible' => floatval($visible), |
||
164 | 'tracked' => floatval($tracked), |
||
165 | ]; |
||
166 | $tags = compact('rrd_def'); |
||
167 | data_update($this->getDeviceArray(), 'canopy-generic-gpsStats', $tags, $fields); |
||
168 | $this->enableGraph('canopy_generic_gpsStats'); |
||
169 | } |
||
170 | |||
171 | $radio = snmp_get_multi_oid($this->getDeviceArray(), ['radioDbmInt.0', 'minRadioDbm.0', 'maxRadioDbm.0', 'radioDbmAvg.0'], '-OQUs', 'WHISP-SM-MIB'); |
||
172 | if (is_numeric($radio['radioDbmInt.0']) && is_numeric($radio['minRadioDbm.0']) && is_numeric($radio['maxRadioDbm.0']) && is_numeric($radio['radioDbmAvg.0'])) { |
||
173 | $rrd_def = RrdDefinition::make() |
||
174 | ->addDataset('dbm', 'GAUGE', -100, 0) |
||
175 | ->addDataset('min', 'GAUGE', -100, 0) |
||
176 | ->addDataset('max', 'GAUGE', -100, 0) |
||
177 | ->addDataset('avg', 'GAUGE', -100, 0); |
||
178 | |||
179 | $fields = [ |
||
180 | 'dbm' => $radio['radioDbmInt.0'], |
||
181 | 'min' => $radio['minRadioDbm.0'], |
||
182 | 'max' => $radio['maxRadioDbm.0'], |
||
183 | 'avg' => $radio['radioDbmAvg.0'], |
||
184 | ]; |
||
185 | $tags = compact('rrd_def'); |
||
186 | data_update($this->getDeviceArray(), 'canopy-generic-radioDbm', $tags, $fields); |
||
187 | $this->enableGraph('canopy_generic_radioDbm'); |
||
188 | } |
||
189 | |||
190 | $dbm = snmp_get_multi_oid($this->getDeviceArray(), ['linkRadioDbmHorizontal.2', 'linkRadioDbmVertical.2'], '-OQUs', 'WHISP-APS-MIB'); |
||
191 | if (is_numeric($dbm['linkRadioDbmHorizontal.2']) && is_numeric($dbm['linkRadioDbmVertical.2'])) { |
||
192 | $rrd_def = RrdDefinition::make() |
||
193 | ->addDataset('horizontal', 'GAUGE', -100, 0) |
||
194 | ->addDataset('vertical', 'GAUGE', -100, 0); |
||
195 | $fields = [ |
||
196 | 'horizontal' => $dbm['linkRadioDbmHorizontal.2'], |
||
197 | 'vertical' => $dbm['linkRadioDbmVertical.2'], |
||
198 | ]; |
||
199 | $tags = compact('rrd_def'); |
||
200 | data_update($this->getDeviceArray(), 'canopy-generic-450-linkRadioDbm', $tags, $fields); |
||
201 | $this->enableGraph('canopy_generic_450_linkRadioDbm'); |
||
202 | } |
||
203 | |||
204 | $lastLevel = str_replace('"', '', snmp_get($this->getDeviceArray(), 'lastPowerLevel.2', '-Ovqn', 'WHISP-APS-MIB')); |
||
205 | if (is_numeric($lastLevel)) { |
||
206 | $rrd_def = RrdDefinition::make()->addDataset('last', 'GAUGE', -100, 0); |
||
207 | $fields = [ |
||
208 | 'last' => $lastLevel, |
||
209 | ]; |
||
210 | $tags = compact('rrd_def'); |
||
211 | data_update($this->getDeviceArray(), 'canopy-generic-450-powerlevel', $tags, $fields); |
||
212 | $this->enableGraph('canopy_generic_450_powerlevel'); |
||
213 | } |
||
214 | |||
215 | $vertical = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.2.2.117.0', '-Ovqn', '')); |
||
216 | $horizontal = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.2.2.118.0', '-Ovqn', '')); |
||
217 | $combined = snmp_get($this->getDeviceArray(), '1.3.6.1.4.1.161.19.3.2.2.21.0', '-Ovqn', ''); |
||
218 | if (is_numeric($vertical) && is_numeric($horizontal) && is_numeric($combined)) { |
||
219 | $rrd_def = RrdDefinition::make() |
||
220 | ->addDataset('vertical', 'GAUGE', -150, 0) |
||
221 | ->addDataset('horizontal', 'GAUGE', -150, 0) |
||
222 | ->addDataset('combined', 'GAUGE', -150, 0); |
||
223 | $fields = [ |
||
224 | 'vertical' => floatval($vertical), |
||
225 | 'horizontal' => floatval($horizontal), |
||
226 | 'combined' => $combined, |
||
227 | ]; |
||
228 | $tags = compact('rrd_def'); |
||
229 | data_update($this->getDeviceArray(), 'canopy-generic-signalHV', $tags, $fields); |
||
230 | $this->enableGraph('canopy_generic_signalHV'); |
||
231 | unset($rrd_def, $vertical, $horizontal, $combined); |
||
232 | } |
||
233 | |||
234 | $horizontal = str_replace('"', '', snmp_get($this->getDeviceArray(), 'radioDbmHorizontal.0', '-Ovqn', 'WHISP-SM-MIB')); |
||
235 | $vertical = str_replace('"', '', snmp_get($this->getDeviceArray(), 'radioDbmVertical.0', '-Ovqn', 'WHISP-SM-MIB')); |
||
236 | if (is_numeric($horizontal) && is_numeric($vertical)) { |
||
237 | $rrd_def = RrdDefinition::make() |
||
238 | ->addDataset('horizontal', 'GAUGE', -100, 100) |
||
239 | ->addDataset('vertical', 'GAUGE', -100, 100); |
||
240 | |||
241 | $fields = [ |
||
242 | 'horizontal' => $horizontal, |
||
243 | 'vertical' => $vertical, |
||
244 | ]; |
||
245 | $tags = compact('rrd_def'); |
||
246 | data_update($this->getDeviceArray(), 'canopy-generic-450-slaveHV', $tags, $fields); |
||
247 | $this->enableGraph('canopy_generic_450_slaveHV'); |
||
248 | } |
||
579 |