| Conditions | 30 |
| Paths | 87 |
| Total Lines | 69 |
| Code Lines | 47 |
| 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 |
||
| 70 | private function _temperature() |
||
| 71 | { |
||
| 72 | if (PSI_OS == 'WINNT') { |
||
| 73 | if ($this->_buf) foreach ($this->_buf as $buffer) { |
||
| 74 | if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) { |
||
| 75 | $dev = new SensorDevice(); |
||
| 76 | if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) { |
||
| 77 | $dev->setName('ThermalZone '.$outbuf[1]); |
||
| 78 | } else { |
||
| 79 | $dev->setName('ThermalZone THM0_0'); |
||
| 80 | } |
||
| 81 | $dev->setValue($value); |
||
| 82 | if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) { |
||
| 83 | $dev->setMax($maxvalue); |
||
| 84 | } |
||
| 85 | $this->mbinfo->setMbTemp($dev); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } else { |
||
| 89 | $notwas = true; |
||
| 90 | foreach (glob('/sys/class/thermal/thermal_zone*/') as $thermalzone) { |
||
| 91 | $thermalzonetemp = $thermalzone.'temp'; |
||
| 92 | $temp = null; |
||
| 93 | if (CommonFunctions::rfts($thermalzonetemp, $temp, 0, 4096, false) && !is_null($temp) && (trim($temp) != "")) { |
||
| 94 | if ($temp >= 1000) { |
||
| 95 | $temp = $temp / 1000; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($temp > -40) { |
||
| 99 | $dev = new SensorDevice(); |
||
| 100 | $dev->setValue($temp); |
||
| 101 | |||
| 102 | $temp_type = null; |
||
| 103 | if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 0, 4096, false) && !is_null($temp_type) && (trim($temp_type) != "")) { |
||
| 104 | $dev->setName($temp_type); |
||
| 105 | } else { |
||
| 106 | $dev->setName("ThermalZone"); |
||
| 107 | } |
||
| 108 | |||
| 109 | $temp_max = null; |
||
| 110 | if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 0, 4096, false) && !is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) { |
||
| 111 | if ($temp_max >= 1000) { |
||
| 112 | $temp_max = $temp_max / 1000; |
||
| 113 | } |
||
| 114 | $dev->setMax($temp_max); |
||
| 115 | } |
||
| 116 | |||
| 117 | $notwas = false; |
||
| 118 | $this->mbinfo->setMbTemp($dev); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | if ($notwas) { |
||
| 123 | foreach (glob('/proc/acpi/thermal_zone/TH*/temperature') as $thermalzone) { |
||
| 124 | $temp = null; |
||
| 125 | if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && (trim($temp) != "")) { |
||
| 126 | $dev = new SensorDevice(); |
||
| 127 | if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) { |
||
| 128 | $dev->setName("ThermalZone ".$name[1]); |
||
| 129 | } else { |
||
| 130 | $dev->setName("ThermalZone"); |
||
| 131 | } |
||
| 132 | $dev->setValue(trim(substr($temp, 23, 4))); |
||
| 133 | $this->mbinfo->setMbTemp($dev); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 152 |
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.