We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 30 |
Paths | 175 |
Total Lines | 118 |
Code Lines | 72 |
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 |
||
51 | public function processDatamap_postProcessFieldArray(string $status, string $table, $id, array &$fieldArray): void // TODO: Add type-hinting for $id when dropping support for PHP 7. |
||
52 | { |
||
53 | if ($status == 'new') { |
||
54 | switch ($table) { |
||
55 | // Field post-processing for table "tx_dlf_documents". |
||
56 | case 'tx_dlf_documents': |
||
57 | // Set sorting field if empty. |
||
58 | if ( |
||
59 | empty($fieldArray['title_sorting']) |
||
60 | && !empty($fieldArray['title']) |
||
61 | ) { |
||
62 | $fieldArray['title_sorting'] = $fieldArray['title']; |
||
63 | } |
||
64 | break; |
||
65 | // Field post-processing for table "tx_dlf_metadata". |
||
66 | // TODO: Include also subentries if available. |
||
67 | case 'tx_dlf_metadata': |
||
68 | // Store field in index if it should appear in lists. |
||
69 | if (!empty($fieldArray['is_listed'])) { |
||
70 | $fieldArray['index_stored'] = 1; |
||
71 | } |
||
72 | // Index field in index if it should be used for auto-completion. |
||
73 | if (!empty($fieldArray['index_autocomplete'])) { |
||
74 | $fieldArray['index_indexed'] = 1; |
||
75 | } |
||
76 | // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures". |
||
77 | case 'tx_dlf_collections': |
||
78 | case 'tx_dlf_libraries': |
||
79 | case 'tx_dlf_structures': |
||
80 | // Set label as index name if empty. |
||
81 | if ( |
||
82 | empty($fieldArray['index_name']) |
||
83 | && !empty($fieldArray['label']) |
||
84 | ) { |
||
85 | $fieldArray['index_name'] = $fieldArray['label']; |
||
86 | } |
||
87 | // Set index name as label if empty. |
||
88 | if ( |
||
89 | empty($fieldArray['label']) |
||
90 | && !empty($fieldArray['index_name']) |
||
91 | ) { |
||
92 | $fieldArray['label'] = $fieldArray['index_name']; |
||
93 | } |
||
94 | // Ensure that index names don't get mixed up with sorting values. |
||
95 | if (substr($fieldArray['index_name'], -8) == '_sorting') { |
||
96 | $fieldArray['index_name'] .= '0'; |
||
97 | } |
||
98 | break; |
||
99 | // Field post-processing for table "tx_dlf_solrcores". |
||
100 | case 'tx_dlf_solrcores': |
||
101 | // Create new Solr core. |
||
102 | $fieldArray['index_name'] = Solr::createCore($fieldArray['index_name']); |
||
103 | if (empty($fieldArray['index_name'])) { |
||
104 | $this->logger->error('Could not create new Apache Solr core'); |
||
105 | // Unset all fields to prevent new database record if Solr core creation failed. |
||
106 | unset($fieldArray); |
||
107 | } |
||
108 | break; |
||
109 | } |
||
110 | } elseif ($status == 'update') { |
||
111 | switch ($table) { |
||
112 | // Field post-processing for table "tx_dlf_metadata". |
||
113 | case 'tx_dlf_metadata': |
||
114 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
115 | ->getQueryBuilderForTable($table); |
||
116 | |||
117 | // Store field in index if it should appear in lists. |
||
118 | if (!empty($fieldArray['is_listed'])) { |
||
119 | $fieldArray['index_stored'] = 1; |
||
120 | } |
||
121 | if ( |
||
122 | isset($fieldArray['index_stored']) |
||
123 | && $fieldArray['index_stored'] == 0 |
||
124 | && !isset($fieldArray['is_listed']) |
||
125 | ) { |
||
126 | // Get current configuration. |
||
127 | $result = $queryBuilder |
||
128 | ->select($table . '.is_listed AS is_listed') |
||
129 | ->from($table) |
||
130 | ->where( |
||
131 | $queryBuilder->expr()->eq($table . '.uid', (int) $id), |
||
132 | Helper::whereExpression($table) |
||
133 | ) |
||
134 | ->setMaxResults(1) |
||
135 | ->execute(); |
||
136 | |||
137 | $resArray = $result->fetchAssociative(); |
||
138 | if (is_array($resArray)) { |
||
139 | // Reset storing to current. |
||
140 | $fieldArray['index_stored'] = $resArray['is_listed']; |
||
141 | } |
||
142 | } |
||
143 | // Index field in index if it should be used for auto-completion. |
||
144 | if (!empty($fieldArray['index_autocomplete'])) { |
||
145 | $fieldArray['index_indexed'] = 1; |
||
146 | } |
||
147 | if ( |
||
148 | isset($fieldArray['index_indexed']) |
||
149 | && $fieldArray['index_indexed'] == 0 |
||
150 | && !isset($fieldArray['index_autocomplete']) |
||
151 | ) { |
||
152 | // Get current configuration. |
||
153 | $result = $queryBuilder |
||
154 | ->select($table . '.index_autocomplete AS index_autocomplete') |
||
155 | ->from($table) |
||
156 | ->where( |
||
157 | $queryBuilder->expr()->eq($table . '.uid', (int) $id), |
||
158 | Helper::whereExpression($table) |
||
159 | ) |
||
160 | ->setMaxResults(1) |
||
161 | ->execute(); |
||
162 | |||
163 | if ($resArray = $result->fetchAssociative()) { |
||
164 | // Reset indexing to current. |
||
165 | $fieldArray['index_indexed'] = $resArray['index_autocomplete']; |
||
166 | } |
||
167 | } |
||
168 | break; |
||
169 | } |
||
412 |