We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 34 |
| Paths | 323 |
| Total Lines | 142 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 45 | public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray) |
||
| 46 | { |
||
| 47 | if ($status == 'new') { |
||
| 48 | switch ($table) { |
||
| 49 | // Field post-processing for table "tx_dlf_documents". |
||
| 50 | case 'tx_dlf_documents': |
||
| 51 | // Set sorting field if empty. |
||
| 52 | if ( |
||
| 53 | empty($fieldArray['title_sorting']) |
||
| 54 | && !empty($fieldArray['title']) |
||
| 55 | ) { |
||
| 56 | $fieldArray['title_sorting'] = $fieldArray['title']; |
||
| 57 | } |
||
| 58 | break; |
||
| 59 | // Field post-processing for table "tx_dlf_metadata". |
||
| 60 | case 'tx_dlf_metadata': |
||
| 61 | // Store field in index if it should appear in lists. |
||
| 62 | if (!empty($fieldArray['is_listed'])) { |
||
| 63 | $fieldArray['index_stored'] = 1; |
||
| 64 | } |
||
| 65 | // Index field in index if it should be used for auto-completion. |
||
| 66 | if (!empty($fieldArray['index_autocomplete'])) { |
||
| 67 | $fieldArray['index_indexed'] = 1; |
||
| 68 | } |
||
| 69 | // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures". |
||
| 70 | case 'tx_dlf_collections': |
||
| 71 | case 'tx_dlf_libraries': |
||
| 72 | case 'tx_dlf_structures': |
||
| 73 | // Set label as index name if empty. |
||
| 74 | if ( |
||
| 75 | empty($fieldArray['index_name']) |
||
| 76 | && !empty($fieldArray['label']) |
||
| 77 | ) { |
||
| 78 | $fieldArray['index_name'] = $fieldArray['label']; |
||
| 79 | } |
||
| 80 | // Set index name as label if empty. |
||
| 81 | if ( |
||
| 82 | empty($fieldArray['label']) |
||
| 83 | && !empty($fieldArray['index_name']) |
||
| 84 | ) { |
||
| 85 | $fieldArray['label'] = $fieldArray['index_name']; |
||
| 86 | } |
||
| 87 | // Ensure that index names don't get mixed up with sorting values. |
||
| 88 | if (substr($fieldArray['index_name'], -8) == '_sorting') { |
||
| 89 | $fieldArray['index_name'] .= '0'; |
||
| 90 | } |
||
| 91 | break; |
||
| 92 | // Field post-processing for table "tx_dlf_solrcores". |
||
| 93 | case 'tx_dlf_solrcores': |
||
| 94 | // Create new Solr core. |
||
| 95 | $fieldArray['index_name'] = Solr::createCore(); |
||
| 96 | if (empty($fieldArray['index_name'])) { |
||
| 97 | Helper::devLog('Could not create new Apache Solr core', DEVLOG_SEVERITY_ERROR); |
||
| 98 | // Solr core could not be created, thus unset field array. |
||
| 99 | $fieldArray = []; |
||
| 100 | } |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | } elseif ($status == 'update') { |
||
| 104 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 105 | ->getQueryBuilderForTable($table); |
||
| 106 | |||
| 107 | switch ($table) { |
||
| 108 | // Field post-processing for table "tx_dlf_metadata". |
||
| 109 | case 'tx_dlf_metadata': |
||
| 110 | // Store field in index if it should appear in lists. |
||
| 111 | if (!empty($fieldArray['is_listed'])) { |
||
| 112 | $fieldArray['index_stored'] = 1; |
||
| 113 | } |
||
| 114 | if ( |
||
| 115 | isset($fieldArray['index_stored']) |
||
| 116 | && $fieldArray['index_stored'] == 0 |
||
| 117 | && !isset($fieldArray['is_listed']) |
||
| 118 | ) { |
||
| 119 | // Get current configuration. |
||
| 120 | $result = $queryBuilder |
||
| 121 | ->select($table . '.is_listed AS is_listed') |
||
| 122 | ->from($table) |
||
| 123 | ->where( |
||
| 124 | $queryBuilder->expr()->eq($table . '.uid', intval($id)), |
||
| 125 | Helper::whereExpression($table) |
||
| 126 | ) |
||
| 127 | ->setMaxResults(1) |
||
| 128 | ->execute(); |
||
| 129 | |||
| 130 | if ($resArray = $result->fetch()) { |
||
| 131 | // Reset storing to current. |
||
| 132 | $fieldArray['index_stored'] = $resArray['is_listed']; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | // Index field in index if it should be used for auto-completion. |
||
| 136 | if (!empty($fieldArray['index_autocomplete'])) { |
||
| 137 | $fieldArray['index_indexed'] = 1; |
||
| 138 | } |
||
| 139 | if ( |
||
| 140 | isset($fieldArray['index_indexed']) |
||
| 141 | && $fieldArray['index_indexed'] == 0 |
||
| 142 | && !isset($fieldArray['index_autocomplete']) |
||
| 143 | ) { |
||
| 144 | // Get current configuration. |
||
| 145 | $result = $queryBuilder |
||
| 146 | ->select($table . '.index_autocomplete AS index_autocomplete') |
||
| 147 | ->from($table) |
||
| 148 | ->where( |
||
| 149 | $queryBuilder->expr()->eq($table . '.uid', intval($id)), |
||
| 150 | Helper::whereExpression($table) |
||
| 151 | ) |
||
| 152 | ->setMaxResults(1) |
||
| 153 | ->execute(); |
||
| 154 | |||
| 155 | if ($resArray = $result->fetch()) { |
||
| 156 | // Reset indexing to current. |
||
| 157 | $fieldArray['index_indexed'] = $resArray['index_autocomplete']; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | // Field post-processing for tables "tx_dlf_metadata" and "tx_dlf_structures". |
||
| 161 | case 'tx_dlf_structures': |
||
| 162 | // The index name should not be changed in production. |
||
| 163 | if (isset($fieldArray['index_name'])) { |
||
| 164 | if (count($fieldArray) < 2) { |
||
| 165 | // Unset the whole field array. |
||
| 166 | $fieldArray = []; |
||
| 167 | } else { |
||
| 168 | // Get current index name. |
||
| 169 | $result = $queryBuilder |
||
| 170 | ->select($table . '.index_autocomplete AS index_autocomplete') |
||
| 171 | ->from($table) |
||
| 172 | ->where( |
||
| 173 | $queryBuilder->expr()->eq($table . '.uid', intval($id)), |
||
| 174 | Helper::whereExpression($table) |
||
| 175 | ) |
||
| 176 | ->setMaxResults(1) |
||
| 177 | ->execute(); |
||
| 178 | |||
| 179 | if ($resArray = $result->fetch()) { |
||
| 180 | // Reset indexing to current. |
||
| 181 | $fieldArray['index_indexed'] = $resArray['index_autocomplete']; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | Helper::devLog('Prevented change of index_name for UID ' . $id . ' in table "' . $table . '"', DEVLOG_SEVERITY_NOTICE); |
||
| 185 | } |
||
| 186 | break; |
||
| 187 | } |
||
| 406 |