| Conditions | 9 |
| Paths | 16 |
| Total Lines | 53 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| 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 | function replace_callback($matches) |
||
| 40 | { |
||
| 41 | $replacement = $matches[3]; |
||
| 42 | switch($matches[1]) |
||
| 43 | { |
||
| 44 | case 'egw_dc_url': |
||
| 45 | $replacement = Api\Framework::getUrl($GLOBALS['egw_info']['server']['webserver_url']); |
||
| 46 | break; |
||
| 47 | case 'egw_dc_logindomain': |
||
| 48 | $replacement = $GLOBALS['egw_info']['user']['domain']; |
||
| 49 | break; |
||
| 50 | case 'egw_dc_username': |
||
| 51 | $replacement = $GLOBALS['egw_info']['user']['account_lid']; |
||
| 52 | break; |
||
| 53 | case 'egw_dc_timeout_socket': |
||
| 54 | case 'egw_dc_timeout_notify': |
||
| 55 | case 'egw_debuging': |
||
| 56 | case 'egw_debuging_level': |
||
| 57 | break; |
||
| 58 | default: |
||
| 59 | $replacement = lang($r=$replacement); |
||
| 60 | /* uncomment this to have missing translations add to en langfile |
||
| 61 | // if no translation found, check if en langfile is writable and add phrase, if not already there |
||
| 62 | if ($r === $replacement) |
||
| 63 | { |
||
| 64 | static $langfile; |
||
| 65 | if (is_null($langfile)) $langfile = EGW_SERVER_ROOT.'/notifications/lang/egw_en.lang'; |
||
| 66 | if (is_writable($langfile) || is_writable(dirname($langfile))) |
||
| 67 | { |
||
| 68 | $content = file_get_contents($langfile); |
||
| 69 | if (!preg_match('/^'.preg_quote($r)."\t/i", $content)) |
||
| 70 | { |
||
| 71 | if (!is_writable($langfile)) unlink($langfile); |
||
| 72 | $content .= "$r\tnotifications\ten\t$r\n"; |
||
| 73 | file_put_contents($langfile, $content); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | }*/ |
||
| 77 | break; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * workaround |
||
| 82 | * Warning: htmlspecialchars() expects parameter 2 to be long, string given |
||
| 83 | */ |
||
| 84 | $htmlscflags = ENT_XML1; |
||
| 85 | |||
| 86 | if (is_string($htmlscflags)) |
||
|
|
|||
| 87 | { |
||
| 88 | $htmlscflags = 16; // #define ENT_XML1 16 |
||
| 89 | } |
||
| 90 | |||
| 91 | return '<'.$matches[1].'>'.htmlspecialchars($replacement, $htmlscflags, Api\Translation::charset()).'</'.$matches[1].'>'; |
||
| 92 | } |
||
| 120 |