Code Duplication    Length = 34-35 lines in 3 locations

phpsysinfo/includes/mb/class.hwmon.inc.php 3 locations

@@ 34-67 (lines=34) @@
31
     *
32
     * @return void
33
     */
34
    private function _temperature($hwpath)
35
    {
36
       $sensor = glob($hwpath."temp*_input", GLOB_NOSORT);
37
       if (($total = count($sensor)) > 0) {
38
            $buf = "";
39
            for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
40
                $dev = new SensorDevice();
41
                $dev->setValue(trim($buf)/1000);
42
                $label = preg_replace("/_input$/", "_label", $sensor[$i]);
43
                $crit = preg_replace("/_input$/", "_crit", $sensor[$i]);
44
                $max = preg_replace("/_input$/", "_max", $sensor[$i]);
45
                $crit_alarm = preg_replace("/_input$/", "_crit_alarm", $sensor[$i]);
46
                if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) {
47
                    $dev->setName(trim($buf));
48
                } else {
49
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
50
                    if ($labelname !== "") {
51
                        $dev->setName($labelname);
52
                    } else {
53
                        $dev->setName('unknown');
54
                    }
55
                }
56
                if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && (trim($buf) != "")) {
57
                    $dev->setMax(trim($buf)/1000);
58
                    if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) {
59
                        $dev->setEvent("Critical Alarm");
60
                    }
61
                } elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) {
62
                    $dev->setMax(trim($buf)/1000);
63
                }
64
                $this->mbinfo->setMbTemp($dev);
65
            }
66
        }
67
    }
68
69
    /**
70
     * get voltage information
@@ 74-108 (lines=35) @@
71
     *
72
     * @return void
73
     */
74
    private function _voltage($hwpath)
75
    {
76
       $sensor = glob($hwpath."in*_input", GLOB_NOSORT);
77
       if (($total = count($sensor)) > 0) {
78
            $buf = "";
79
            for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
80
                $dev = new SensorDevice();
81
                $dev->setValue(trim($buf)/1000);
82
                $label = preg_replace("/_input$/", "_label", $sensor[$i]);
83
                $alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]);
84
                $max = preg_replace("/_input$/", "_max", $sensor[$i]);
85
                $min = preg_replace("/_input$/", "_min", $sensor[$i]);
86
                if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) {
87
                    $dev->setName(trim($buf));
88
                } else {
89
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
90
                    if ($labelname !== "") {
91
                        $dev->setName($labelname);
92
                    } else {
93
                        $dev->setName('unknown');
94
                    }
95
                }
96
                if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) {
97
                    $dev->setMax(trim($buf)/1000);
98
                }
99
                if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) {
100
                    $dev->setMin(trim($buf)/1000);
101
                }
102
                if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) {
103
                    $dev->setEvent("Alarm");
104
                }
105
                $this->mbinfo->setMbVolt($dev);
106
            }
107
        }
108
    }
109
110
    /**
111
     * get fan information
@@ 200-234 (lines=35) @@
197
     *
198
     * @return void
199
     */
200
    private function _current($hwpath)
201
    {
202
       $sensor = glob($hwpath."curr*_input", GLOB_NOSORT);
203
       if (($total = count($sensor)) > 0) {
204
            $buf = "";
205
            for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
206
                $dev = new SensorDevice();
207
                $dev->setValue(trim($buf)/1000);
208
                $label = preg_replace("/_input$/", "_label", $sensor[$i]);
209
                $alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]);
210
                $max = preg_replace("/_input$/", "_max", $sensor[$i]);
211
                $min = preg_replace("/_input$/", "_min", $sensor[$i]);
212
                if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) {
213
                    $dev->setName(trim($buf));
214
                } else {
215
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
216
                    if ($labelname !== "") {
217
                        $dev->setName($labelname);
218
                    } else {
219
                        $dev->setName('unknown');
220
                    }
221
                }
222
                if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) {
223
                    $dev->setMax(trim($buf)/1000);
224
                }
225
                if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) {
226
                    $dev->setMin(trim($buf)/1000);
227
                }
228
                if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) {
229
                    $dev->setEvent("Alarm");
230
                }
231
                $this->mbinfo->setMbCurrent($dev);
232
            }
233
        }
234
    }
235
236
    /**
237
     * get the information