We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 39 |
| Paths | 343 |
| Total Lines | 161 |
| Code Lines | 105 |
| 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 |
||
| 40 | public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $pObj) { |
||
|
1 ignored issue
–
show
|
|||
| 41 | if ($status == 'new') { |
||
| 42 | switch ($table) { |
||
| 43 | // Field post-processing for table "tx_dlf_documents". |
||
| 44 | case 'tx_dlf_documents': |
||
| 45 | // Set sorting field if empty. |
||
| 46 | if (empty($fieldArray['title_sorting']) |
||
| 47 | && !empty($fieldArray['title'])) { |
||
| 48 | $fieldArray['title_sorting'] = $fieldArray['title']; |
||
| 49 | } |
||
| 50 | break; |
||
| 51 | // Field post-processing for table "tx_dlf_metadata". |
||
| 52 | case 'tx_dlf_metadata': |
||
| 53 | // Store field in index if it should appear in lists. |
||
| 54 | if (!empty($fieldArray['is_listed'])) { |
||
| 55 | $fieldArray['index_stored'] = 1; |
||
| 56 | } |
||
| 57 | // Index field in index if it should be used for auto-completion. |
||
| 58 | if (!empty($fieldArray['index_autocomplete'])) { |
||
| 59 | $fieldArray['index_indexed'] = 1; |
||
| 60 | } |
||
| 61 | // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures". |
||
| 62 | case 'tx_dlf_collections': |
||
| 63 | case 'tx_dlf_libraries': |
||
| 64 | case 'tx_dlf_structures': |
||
| 65 | // Set label as index name if empty. |
||
| 66 | if (empty($fieldArray['index_name']) |
||
| 67 | && !empty($fieldArray['label'])) { |
||
| 68 | $fieldArray['index_name'] = $fieldArray['label']; |
||
| 69 | } |
||
| 70 | // Set index name as label if empty. |
||
| 71 | if (empty($fieldArray['label']) |
||
| 72 | && !empty($fieldArray['index_name'])) { |
||
| 73 | $fieldArray['label'] = $fieldArray['index_name']; |
||
| 74 | } |
||
| 75 | // Ensure that index names don't get mixed up with sorting values. |
||
| 76 | if (substr($fieldArray['index_name'], -8) == '_sorting') { |
||
| 77 | $fieldArray['index_name'] .= '0'; |
||
| 78 | } |
||
| 79 | break; |
||
| 80 | // Field post-processing for table "tx_dlf_solrcores". |
||
| 81 | case 'tx_dlf_solrcores': |
||
| 82 | // Get number of existing cores. |
||
| 83 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 84 | '*', |
||
| 85 | 'tx_dlf_solrcores', |
||
| 86 | '', |
||
| 87 | '', |
||
| 88 | '', |
||
| 89 | '' |
||
| 90 | ); |
||
| 91 | // Get first unused core number. |
||
| 92 | $coreNumber = Solr::solrGetCoreNumber($GLOBALS['TYPO3_DB']->sql_num_rows($result)); |
||
| 93 | // Get Solr credentials. |
||
| 94 | $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']); |
||
| 95 | $solrInfo = Solr::getSolrConnectionInfo(); |
||
| 96 | // Prepend username and password to hostname. |
||
| 97 | if ($solrInfo['username'] |
||
| 98 | && $solrInfo['password']) { |
||
| 99 | $host = $solrInfo['username'].':'.$solrInfo['password'].'@'.$solrInfo['host']; |
||
| 100 | } else { |
||
| 101 | $host = $solrInfo['host']; |
||
| 102 | } |
||
| 103 | $context = stream_context_create([ |
||
| 104 | 'http' => [ |
||
| 105 | 'method' => 'GET', |
||
| 106 | 'user_agent' => ($conf['useragent'] ? $conf['useragent'] : ini_get('user_agent')) |
||
| 107 | ] |
||
| 108 | ]); |
||
| 109 | // Build request for adding new Solr core. |
||
| 110 | // @see http://wiki.apache.org/solr/CoreAdmin |
||
| 111 | $url = $solrInfo['scheme'].'://'.$host.':'.$solrInfo['port'].'/'.$solrInfo['path'].'/admin/cores?wt=xml&action=CREATE&name=dlfCore'.$coreNumber.'&instanceDir=dlfCore'.$coreNumber.'&dataDir=data&configSet=dlf'; |
||
| 112 | $response = @simplexml_load_string(file_get_contents($url, FALSE, $context)); |
||
| 113 | // Process response. |
||
| 114 | if ($response) { |
||
| 115 | $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]'); |
||
| 116 | if ($status |
||
| 117 | && $status[0] == 0) { |
||
| 118 | $fieldArray['index_name'] = 'dlfCore'.$coreNumber; |
||
| 119 | return; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | Helper::devLog('Could not create new Apache Solr core "dlfCore'.$coreNumber.'"', DEVLOG_SEVERITY_ERROR); |
||
| 123 | // Solr core could not be created, thus unset field array. |
||
| 124 | $fieldArray = []; |
||
| 125 | break; |
||
| 126 | } |
||
| 127 | } elseif ($status == 'update') { |
||
| 128 | switch ($table) { |
||
| 129 | // Field post-processing for table "tx_dlf_metadata". |
||
| 130 | case 'tx_dlf_metadata': |
||
| 131 | // Store field in index if it should appear in lists. |
||
| 132 | if (!empty($fieldArray['is_listed'])) { |
||
| 133 | $fieldArray['index_stored'] = 1; |
||
| 134 | } |
||
| 135 | if (isset($fieldArray['index_stored']) |
||
| 136 | && $fieldArray['index_stored'] == 0 |
||
| 137 | && !isset($fieldArray['is_listed'])) { |
||
| 138 | // Get current configuration. |
||
| 139 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 140 | $table.'.is_listed AS is_listed', |
||
| 141 | $table, |
||
| 142 | $table.'.uid='.intval($id) |
||
| 143 | .Helper::whereClause($table), |
||
| 144 | '', |
||
| 145 | '', |
||
| 146 | '1' |
||
| 147 | ); |
||
| 148 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 149 | // Reset storing to current. |
||
| 150 | list ($fieldArray['index_stored']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | // Index field in index if it should be used for auto-completion. |
||
| 154 | if (!empty($fieldArray['index_autocomplete'])) { |
||
| 155 | $fieldArray['index_indexed'] = 1; |
||
| 156 | } |
||
| 157 | if (isset($fieldArray['index_indexed']) |
||
| 158 | && $fieldArray['index_indexed'] == 0 |
||
| 159 | && !isset($fieldArray['index_autocomplete'])) { |
||
| 160 | // Get current configuration. |
||
| 161 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 162 | $table.'.index_autocomplete AS index_autocomplete', |
||
| 163 | $table, |
||
| 164 | $table.'.uid='.intval($id) |
||
| 165 | .Helper::whereClause($table), |
||
| 166 | '', |
||
| 167 | '', |
||
| 168 | '1' |
||
| 169 | ); |
||
| 170 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 171 | // Reset indexing to current. |
||
| 172 | list ($fieldArray['index_indexed']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | // Field post-processing for tables "tx_dlf_metadata" and "tx_dlf_structures". |
||
| 176 | case 'tx_dlf_structures': |
||
| 177 | // The index name should not be changed in production. |
||
| 178 | if (isset($fieldArray['index_name'])) { |
||
| 179 | if (count($fieldArray) < 2) { |
||
| 180 | // Unset the whole field array. |
||
| 181 | $fieldArray = []; |
||
| 182 | } else { |
||
| 183 | // Get current index name. |
||
| 184 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 185 | $table.'.index_name AS index_name', |
||
| 186 | $table, |
||
| 187 | $table.'.uid='.intval($id) |
||
| 188 | .Helper::whereClause($table), |
||
| 189 | '', |
||
| 190 | '', |
||
| 191 | '1' |
||
| 192 | ); |
||
| 193 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 194 | // Reset index name to current. |
||
| 195 | list ($fieldArray['index_name']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result); |
||
| 196 | } |
||
| 197 | } |
||
| 198 | Helper::devLog('Prevented change of index_name for UID '.$id.' in table "'.$table.'"', DEVLOG_SEVERITY_NOTICE); |
||
| 199 | } |
||
| 200 | break; |
||
| 201 | } |
||
| 321 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.