Conditions | 14 |
Paths | 13 |
Total Lines | 22 |
Code Lines | 13 |
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 |
||
83 | protected static function run_plugin_hooks($method, array $data) |
||
84 | { |
||
85 | foreach(Account::search((int)$data['account_id'], 'params') as $params) |
||
86 | { |
||
87 | if (!Account::is_multiple($params)) continue; // no need to waste time on personal accounts |
||
88 | |||
89 | try { |
||
90 | $account = new Account($params); |
||
91 | if ($account->acc_smtp_type != __NAMESPACE__.'\\Smtp' && ($smtp = $account->smtpServer(true)) && |
||
|
|||
92 | is_a($smtp, __NAMESPACE__.'\\Smtp') && get_class($smtp) != __NAMESPACE__.'\\Smtp') |
||
93 | { |
||
94 | $smtp->$method($data); |
||
95 | } |
||
96 | if ($account->acc_imap_type != __NAMESPACE__.'\\Imap' && $account->acc_imap_admin_username && |
||
97 | $account->acc_imap_admin_password && ($imap = $account->imapServer(true)) && |
||
98 | is_a($imap, __NAMESPACE__.'\\Imap') && get_class($imap) != __NAMESPACE__.'\\Imap') |
||
99 | { |
||
100 | $imap->$method($data); |
||
101 | } |
||
102 | } |
||
103 | catch(\Exception $e) { |
||
104 | _egw_log_exception($e); |
||
105 | // ignore exception, without stalling other hooks |
||
110 |
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.