| Conditions | 13 |
| Paths | 116 |
| Total Lines | 63 |
| Code Lines | 38 |
| 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 |
||
| 37 | function index(array $_content=null, $msg='') |
||
| 38 | { |
||
| 39 | if (is_array($_content)) |
||
| 40 | { |
||
| 41 | //_debug_array($_content); |
||
| 42 | if (isset($_content['button'])) |
||
| 43 | { |
||
| 44 | $action = key($_content['button']); |
||
| 45 | unset($_content['button']); |
||
| 46 | } |
||
| 47 | elseif($_content['rows']['delete']) |
||
| 48 | { |
||
| 49 | $action = key($_content['rows']['delete']); |
||
| 50 | unset($_content['rows']['delete']); |
||
| 51 | } |
||
| 52 | switch($action) |
||
| 53 | { |
||
| 54 | case 'save': |
||
| 55 | case 'apply': |
||
| 56 | $saved = 0; |
||
| 57 | foreach($_content['rows'] as $data) |
||
| 58 | { |
||
| 59 | if (!empty($data['phrase'])) |
||
| 60 | { |
||
| 61 | Api\Translation::write('en', 'custom', strtolower(trim($data['phrase'])), $data['translation']); |
||
| 62 | ++$saved; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | if ($saved) $msg = lang('%1 phrases saved.', $saved); |
||
|
|
|||
| 66 | if ($action == 'apply') break; |
||
| 67 | // fall through |
||
| 68 | case 'cancel': |
||
| 69 | Egw::redirect_link('/admin/index.php'); |
||
| 70 | break; |
||
| 71 | |||
| 72 | default: // line to delete; |
||
| 73 | if (!empty($_content['rows'][$action]['phrase'])) |
||
| 74 | { |
||
| 75 | Api\Translation::write('en', 'custom', strtolower(trim($_content['rows'][$action]['phrase'])), null); |
||
| 76 | $msg = lang('Phrase deleted'); |
||
| 77 | } |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | $content = array('rows' => array()); |
||
| 82 | foreach(Api\Translation::load_app('custom', 'en') as $phrase => $translation) |
||
| 83 | { |
||
| 84 | $content['rows'][++$row] = array( |
||
| 85 | 'phrase' => $phrase, |
||
| 86 | 'translation' => $translation, |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | // one empty line to add new translations |
||
| 90 | $content['rows'][++$row] = array( |
||
| 91 | 'phrase' => '', |
||
| 92 | 'translation' => '', |
||
| 93 | ); |
||
| 94 | $readonlys["delete[$row]"] = true; // no delete for empty row |
||
| 95 | $content['msg'] = $msg; |
||
| 96 | |||
| 97 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Custom translation'); |
||
| 98 | $tpl = new Etemplate('admin.customtranslation'); |
||
| 99 | $tpl->exec('admin.admin_customtranslation.index', $content, array(), $readonlys); |
||
| 100 | } |
||
| 102 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.