| Conditions | 35 |
| Paths | 11 |
| Total Lines | 119 |
| Code Lines | 85 |
| Lines | 25 |
| Ratio | 21.01 % |
| 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 |
||
| 45 | public function __construct($enc) |
||
| 46 | { |
||
| 47 | parent::__construct(__CLASS__, $enc); |
||
| 48 | switch (strtolower(PSI_PLUGIN_SNMPPINFO_ACCESS)) { |
||
| 49 | case 'command': |
||
| 50 | if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
||
| 51 | if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
||
| 52 | $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 53 | } else { |
||
| 54 | $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 55 | } |
||
| 56 | foreach ($printers as $printer) { |
||
| 57 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG); |
||
| 58 | if (strlen($buffer) > 0) { |
||
| 59 | $this->_filecontent[$printer] = $buffer; |
||
| 60 | |||
| 61 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG); |
||
| 62 | if (strlen($buffer2) > 0) { |
||
| 63 | $this->_filecontent[$printer] .= "\n".$buffer2; |
||
| 64 | } |
||
| 65 | CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 ".$printer." .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG); |
||
| 66 | if (strlen($buffer3) > 0) { |
||
| 67 | $this->_filecontent[$printer] .= "\n".$buffer3; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | break; |
||
| 73 | case 'php-snmp': |
||
| 74 | if (!extension_loaded("snmp")) { |
||
| 75 | $this->global_error->addError("Requirements error", "SNMPPInfo 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_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
||
| 81 | if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
||
| 82 | $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 83 | } else { |
||
| 84 | $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 85 | } |
||
| 86 | foreach ($printers as $printer) { |
||
| 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($printer, "public", ".1.3.6.1.2.1.1.5", 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($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1); |
||
| 109 | if (! PSI_DEBUG) { |
||
| 110 | error_reporting($old_err_rep); /* restore error level */ |
||
| 111 | set_error_handler('errorHandlerPsi'); /* restore error handler */ |
||
| 112 | } |
||
| 113 | View Code Duplication | if (! empty($bufferarr2)) { |
|
| 114 | foreach ($bufferarr2 as $id=>$string) { |
||
| 115 | $buffer .= $id." = ".$string."\n"; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if (! PSI_DEBUG) { |
||
| 120 | restore_error_handler(); /* default error handler */ |
||
| 121 | $old_err_rep = error_reporting(); |
||
| 122 | error_reporting(E_ERROR); /* fatal errors only */ |
||
| 123 | } |
||
| 124 | $bufferarr3=snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1); |
||
| 125 | if (! PSI_DEBUG) { |
||
| 126 | error_reporting($old_err_rep); /* restore error level */ |
||
| 127 | set_error_handler('errorHandlerPsi'); /* restore error handler */ |
||
| 128 | } |
||
| 129 | View Code Duplication | if (! empty($bufferarr3)) { |
|
| 130 | foreach ($bufferarr3 as $id=>$string) { |
||
| 131 | $buffer .= $id." = ".$string."\n"; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if (strlen(trim($buffer)) > 0) { |
||
| 136 | $this->_filecontent[$printer] = $buffer; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | break; |
||
| 142 | case 'data': |
||
| 143 | View Code Duplication | if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
|
| 144 | if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) { |
||
| 145 | $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 146 | } else { |
||
| 147 | $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES); |
||
| 148 | } |
||
| 149 | $pn=0; |
||
| 150 | foreach ($printers as $printer) { |
||
| 151 | $buffer=""; |
||
| 152 | if (CommonFunctions::rfts(APP_ROOT."/data/snmppinfo{$pn}.txt", $buffer) && !empty($buffer)) { |
||
| 153 | $this->_filecontent[$printer] = $buffer; |
||
| 154 | } |
||
| 155 | $pn++; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | break; |
||
| 159 | default: |
||
| 160 | $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in phpsysinfo.ini"); |
||
| 161 | break; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 234 |
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.