| Conditions | 17 |
| Paths | 15 |
| Total Lines | 55 |
| Code Lines | 40 |
| Lines | 17 |
| Ratio | 30.91 % |
| 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 |
||
| 51 | public function __construct($enc) |
||
| 52 | { |
||
| 53 | parent::__construct(__CLASS__, $enc); |
||
| 54 | switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) { |
||
| 55 | case 'command': |
||
| 56 | if (PSI_OS == 'WINNT') { |
||
| 57 | try { |
||
| 58 | $objLocator = new COM("WbemScripting.SWbemLocator"); |
||
| 59 | $wmi = $objLocator->ConnectServer(); |
||
| 60 | $process_wmi = $wmi->InstancesOf('Win32_Process'); |
||
| 61 | foreach ($process_wmi as $process) { |
||
| 62 | $this->_filecontent[] = array(strtolower(trim($process->Caption)), trim($process->ProcessId)); |
||
| 63 | } |
||
| 64 | } catch (Exception $e) { |
||
| 65 | } |
||
| 66 | } else { |
||
| 67 | if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) { |
||
| 68 | View Code Duplication | if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) { |
|
| 69 | $processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES); |
||
| 70 | } else { |
||
| 71 | $processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES); |
||
| 72 | } |
||
| 73 | if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX === true) { |
||
| 74 | View Code Duplication | foreach ($processes as $process) { |
|
| 75 | CommonFunctions::executeProgram("pgrep", "-n -x ".$process, $buffer, PSI_DEBUG); |
||
| 76 | if (strlen($buffer) > 0) { |
||
| 77 | $this->_filecontent[] = array($process, $buffer); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } else { |
||
| 81 | View Code Duplication | foreach ($processes as $process) { |
|
| 82 | CommonFunctions::executeProgram("pidof", "-s ".$process, $buffer, PSI_DEBUG); |
||
| 83 | if (strlen($buffer) > 0) { |
||
| 84 | $this->_filecontent[] = array($process, $buffer); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | break; |
||
| 91 | case 'data': |
||
| 92 | CommonFunctions::rfts(APP_ROOT."/data/psstatus.txt", $buffer); |
||
| 93 | $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY); |
||
| 94 | foreach ($processes as $process) { |
||
| 95 | $ps = preg_split("/[\s]?\|[\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY); |
||
| 96 | if (count($ps) == 2) { |
||
| 97 | $this->_filecontent[] = array(trim($ps[0]), trim($ps[1])); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | break; |
||
| 101 | default: |
||
| 102 | $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini"); |
||
| 103 | break; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 180 |
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.