| Conditions | 14 |
| Paths | 8192 |
| Total Lines | 77 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 32 | function set_constants() |
||
| 33 | { |
||
| 34 | // Get some constants from a configuration file. |
||
| 35 | $conf_fn = 'palma.ini'; |
||
| 36 | if (!file_exists($conf_fn)) { |
||
| 37 | $conf_fn = '/etc/palma.ini'; |
||
| 38 | } |
||
| 39 | $conf = parse_ini_file($conf_fn); |
||
| 40 | //~ print_r($conf); |
||
| 41 | |||
| 42 | // Entries in group 'display'. |
||
| 43 | if (array_key_exists('id', $conf)) { |
||
| 44 | define('CONFIG_DISPLAY', $conf['id']); |
||
| 45 | } else { |
||
| 46 | define('CONFIG_DISPLAY', ':1'); |
||
| 47 | } |
||
| 48 | if (array_key_exists('ssh', $conf)) { |
||
| 49 | define('CONFIG_SSH', $conf['ssh']); |
||
| 50 | } // There is no default value for CONFIG_SSH. |
||
| 51 | |||
| 52 | // Entries in group 'general'. |
||
| 53 | if (array_key_exists('password', $conf)) { |
||
| 54 | define('CONFIG_PASSWORD', $conf['password']); |
||
| 55 | } else { |
||
| 56 | define('CONFIG_PASSWORD', false); |
||
| 57 | } |
||
| 58 | if (array_key_exists('pin', $conf)) { |
||
| 59 | define('CONFIG_PIN', $conf['pin']); |
||
| 60 | } else { |
||
| 61 | define('CONFIG_PIN', true); |
||
| 62 | } |
||
| 63 | if (array_key_exists('stationname', $conf)) { |
||
| 64 | define('CONFIG_STATIONNAME', $conf['stationname']); |
||
| 65 | } else { |
||
| 66 | define( |
||
| 67 | 'CONFIG_STATIONNAME', |
||
| 68 | str_replace(array("\r", "\n", " "), '', `hostname -f`) |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | if (array_key_exists('theme', $conf)) { |
||
| 72 | define('CONFIG_THEME', $conf['theme']); |
||
| 73 | } else { |
||
| 74 | define('CONFIG_THEME', 'demo/simple'); |
||
| 75 | } |
||
| 76 | |||
| 77 | // Entries in group 'path'. |
||
| 78 | if (array_key_exists('start_url', $conf)) { |
||
| 79 | define('CONFIG_START_URL', $conf['start_url']); |
||
| 80 | } else { |
||
| 81 | // By default we use the FQDN of the host |
||
| 82 | define( |
||
| 83 | 'CONFIG_START_URL', |
||
| 84 | 'http://' . str_replace(array("\r", "\n", " "), '', `hostname -f`) . '/' |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | if (array_key_exists('control_file', $conf)) { |
||
| 88 | define('CONFIG_CONTROL_FILE', $conf['control_file']); |
||
| 89 | } else { |
||
| 90 | define('CONFIG_CONTROL_FILE', CONFIG_START_URL . 'control.php'); |
||
| 91 | } |
||
| 92 | if (array_key_exists('policy', $conf)) { |
||
| 93 | define('CONFIG_POLICY', $conf['policy']); |
||
| 94 | } // There is no default value for CONFIG_POLICY. |
||
| 95 | if (array_key_exists('upload_dir', $conf)) { |
||
| 96 | define('CONFIG_UPLOAD_DIR', $conf['upload_dir']); |
||
| 97 | } else { |
||
| 98 | define('CONFIG_UPLOAD_DIR', '/tmp/palma'); |
||
| 99 | } |
||
| 100 | if (array_key_exists('institution_url', $conf)) { |
||
| 101 | define('CONFIG_INSTITUTION_URL', $conf['institution_url']); |
||
| 102 | } else { |
||
| 103 | define('CONFIG_INSTITUTION_URL', ''); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Entries in group 'monitoring'. |
||
| 107 | if (array_key_exists('monitor_url', $conf)) { |
||
| 108 | define('CONFIG_MONITOR_URL', $conf['monitor_url']); |
||
| 109 | } // There is no default value for CONFIG_MONITOR_URL. |
||
| 112 |