Conditions | 29 |
Paths | 8 |
Total Lines | 102 |
Code Lines | 75 |
Lines | 20 |
Ratio | 19.61 % |
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 |
||
39 | public function __construct() |
||
40 | { |
||
41 | parent::__construct(); |
||
42 | switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) { |
||
43 | case 'command': |
||
44 | if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) { |
||
45 | View Code Duplication | if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) { |
|
46 | $upss = eval(PSI_UPS_SNMPUPS_LIST); |
||
47 | } else { |
||
48 | $upss = array(PSI_UPS_SNMPUPS_LIST); |
||
49 | } |
||
50 | foreach ($upss as $ups) { |
||
51 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$ups." .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG); |
||
52 | if (strlen($buffer) > 0) { |
||
53 | $this->_output[$ups] = $buffer; |
||
54 | $buffer = ""; |
||
55 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$ups." .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG); |
||
56 | if (strlen($buffer) > 0) { |
||
57 | $this->_output[$ups] .= "\n".$buffer; |
||
58 | } |
||
59 | $buffer = ""; |
||
60 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$ups." .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG); |
||
61 | if (strlen($buffer) > 0) { |
||
62 | $this->_output[$ups] .= "\n".$buffer; |
||
63 | } |
||
64 | $buffer = ""; |
||
65 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$ups." .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG); |
||
66 | if (strlen($buffer) > 0) { |
||
67 | $this->_output[$ups] .= "\n".$buffer; |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | break; |
||
73 | case 'php-snmp': |
||
74 | if (!extension_loaded("snmp")) { |
||
75 | $this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly"); |
||
76 | break; |
||
77 | } |
||
78 | snmp_set_valueretrieval(SNMP_VALUE_LIBRARY); |
||
79 | snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC); |
||
80 | if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) { |
||
81 | View Code Duplication | if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) { |
|
82 | $upss = eval(PSI_UPS_SNMPUPS_LIST); |
||
83 | } else { |
||
84 | $upss = array(PSI_UPS_SNMPUPS_LIST); |
||
85 | } |
||
86 | foreach ($upss as $ups) { |
||
87 | if (! PSI_DEBUG) { |
||
88 | restore_error_handler(); /* default error handler */ |
||
89 | $old_err_rep = error_reporting(); |
||
90 | error_reporting(E_ERROR); /* fatal errors only */ |
||
91 | } |
||
92 | $bufferarr=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000, 1); |
||
93 | if (! PSI_DEBUG) { |
||
94 | error_reporting($old_err_rep); /* restore error level */ |
||
95 | set_error_handler('errorHandlerPsi'); /* restore error handler */ |
||
96 | } |
||
97 | if (! empty($bufferarr)) { |
||
98 | $buffer=""; |
||
99 | foreach ($bufferarr as $id=>$string) { |
||
100 | $buffer .= $id." = ".$string."\n"; |
||
101 | } |
||
102 | |||
103 | if (! PSI_DEBUG) { |
||
104 | restore_error_handler(); /* default error handler */ |
||
105 | $old_err_rep = error_reporting(); |
||
106 | error_reporting(E_ERROR); /* fatal errors only */ |
||
107 | } |
||
108 | $bufferarr2=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000, 1); |
||
109 | $bufferarr3=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000, 1); |
||
110 | $bufferarr4=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000, 1); |
||
111 | if (! PSI_DEBUG) { |
||
112 | error_reporting($old_err_rep); /* restore error level */ |
||
113 | set_error_handler('errorHandlerPsi'); /* restore error handler */ |
||
114 | } |
||
115 | if (! empty($bufferarr2)) { |
||
116 | foreach ($bufferarr2 as $id=>$string) { |
||
117 | $buffer .= $id." = ".$string."\n"; |
||
118 | } |
||
119 | View Code Duplication | if (! empty($bufferarr3)) { |
|
120 | foreach ($bufferarr3 as $id=>$string) { |
||
121 | $buffer .= $id." = ".$string."\n"; |
||
122 | } |
||
123 | } } |
||
124 | View Code Duplication | if (! empty($bufferarr4)) { |
|
125 | foreach ($bufferarr4 as $id=>$string) { |
||
126 | $buffer .= $id." = ".$string."\n"; |
||
127 | } |
||
128 | } |
||
129 | if (strlen(trim($buffer)) > 0) { |
||
130 | $this->_output[$ups] = $buffer; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | break; |
||
136 | default: |
||
137 | $this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini"); |
||
138 | break; |
||
139 | } |
||
140 | } |
||
141 | |||
287 |
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.