| Conditions | 5 |
| Paths | 12 |
| Total Lines | 61 |
| Code Lines | 38 |
| Lines | 2 |
| Ratio | 3.28 % |
| 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 |
||
| 72 | function smf_db_search_query($identifier, $db_string, $db_values = array(), $connection = null) |
||
| 73 | { |
||
| 74 | global $smcFunc; |
||
| 75 | |||
| 76 | $replacements = array( |
||
| 77 | 'create_tmp_log_search_topics' => array( |
||
| 78 | '~mediumint\(\d\)~i' => 'int', |
||
| 79 | '~unsigned~i' => '', |
||
| 80 | '~ENGINE=MEMORY~i' => '', |
||
| 81 | ), |
||
| 82 | 'create_tmp_log_search_messages' => array( |
||
| 83 | '~mediumint\(\d\)~i' => 'int', |
||
| 84 | '~unsigned~i' => '', |
||
| 85 | '~ENGINE=MEMORY~i' => '', |
||
| 86 | ), |
||
| 87 | 'drop_tmp_log_search_topics' => array( |
||
| 88 | '~IF\sEXISTS~i' => '', |
||
| 89 | ), |
||
| 90 | 'drop_tmp_log_search_messages' => array( |
||
| 91 | '~IF\sEXISTS~i' => '', |
||
| 92 | ), |
||
| 93 | 'insert_into_log_messages_fulltext' => array( |
||
| 94 | '~LIKE~i' => 'iLIKE', |
||
| 95 | '~NOT\sLIKE~i' => '~NOT iLIKE', |
||
| 96 | '~NOT\sRLIKE~i' => '!~*', |
||
| 97 | '~RLIKE~i' => '~*', |
||
| 98 | ), |
||
| 99 | 'insert_log_search_results_subject' => array( |
||
| 100 | '~LIKE~i' => 'iLIKE', |
||
| 101 | '~NOT\sLIKE~i' => 'NOT iLIKE', |
||
| 102 | '~NOT\sRLIKE~i' => '!~*', |
||
| 103 | '~RLIKE~i' => '~*', |
||
| 104 | ), |
||
| 105 | ); |
||
| 106 | |||
| 107 | View Code Duplication | if (isset($replacements[$identifier])) |
|
| 108 | $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
||
| 109 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
||
| 110 | { |
||
| 111 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
||
| 112 | if ($smcFunc['db_support_ignore']){ |
||
| 113 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
||
| 114 | $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
||
| 115 | } |
||
| 116 | else |
||
| 117 | { |
||
| 118 | // Don't error on multi-insert. |
||
| 119 | $db_values['db_error_skip'] = true; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | //fix double quotes |
||
| 124 | if ($identifier == 'insert_into_log_messages_fulltext') |
||
| 125 | $db_values = str_replace('"', "'", $db_values); |
||
| 126 | |||
| 127 | $return = $smcFunc['db_query']('', $db_string, |
||
| 128 | $db_values, $connection |
||
| 129 | ); |
||
| 130 | |||
| 131 | return $return; |
||
| 132 | } |
||
| 133 | |||
| 195 | ?> |
||
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignoreannotation.See also the PhpDoc documentation for @ignore.