Conditions | 6 |
Paths | 6 |
Total Lines | 68 |
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 |
||
176 | function getCacheDetails(Connection $connection, string $searchText = "", int $id = 0) |
||
177 | : array { |
||
178 | $fetchedCaches = []; |
||
179 | |||
180 | if ($id != 0) { |
||
181 | $request = new CachesRepository($connection); |
||
182 | |||
183 | $fetchedCache = $request->fetchOneBy(['cache_id' => $id]); |
||
184 | |||
185 | if ($fetchedCache) { |
||
186 | $searchText = $fetchedCache->wpOc; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | if ($searchText != "") { |
||
191 | // so sieht die SQL-Vorlage aus.. |
||
192 | // SELECT caches.cache_id, caches.name, caches.wp_oc, caches.wp_gc, |
||
193 | // caches.date_hidden, caches.date_created, caches.is_publishdate, caches.latitude, caches.longitude, |
||
194 | // caches.difficulty, caches.terrain, caches.size, caches.logpw, |
||
195 | // cache_status.name as cache_status_name, cache_type.icon_large as cache_type_picture, |
||
196 | // cache_size.name as cache_size_name, user.username |
||
197 | // FROM caches |
||
198 | // INNER JOIN user ON caches.user_id = user.user_id |
||
199 | // INNER JOIN cache_status ON caches.status = cache_status.id |
||
200 | // INNER JOIN cache_type ON caches.type = cache_type.id |
||
201 | // INNER JOIN cache_size ON caches.size = cache_size.id |
||
202 | // WHERE caches.wp_oc = "' . $searchtext . '" |
||
203 | $qb = $connection->createQueryBuilder(); |
||
204 | $qb |
||
205 | ->select('caches.cache_id', 'caches.name', 'caches.wp_oc', 'caches.wp_gc') |
||
206 | ->addSelect('caches.date_hidden', 'caches.date_created', 'caches.is_publishdate', 'caches.latitude', 'caches.longitude') |
||
207 | ->addSelect('caches.difficulty', 'caches.terrain', 'caches.size', 'caches.logpw') |
||
208 | ->addSelect('cache_status.name as cache_status_name', 'cache_type.icon_large as cache_type_picture') |
||
209 | ->addSelect('cache_size.name as cache_size_name', 'user.username') |
||
210 | ->from('caches') |
||
211 | ->innerJoin('caches', 'user', 'user', 'caches.user_id = user.user_id') |
||
212 | ->innerJoin('caches', 'cache_status', 'cache_status', 'caches.status = cache_status.id') |
||
213 | ->innerJoin('caches', 'cache_type', 'cache_type', 'caches.type = cache_type.id') |
||
214 | ->innerJoin('caches', 'cache_size', 'cache_size', 'caches.size = cache_size.id') |
||
215 | ->where('caches.wp_oc = :searchTerm') |
||
216 | ->setParameters(['searchTerm' => $searchText]) |
||
217 | ->orderBy('caches.wp_oc', 'DESC'); |
||
218 | |||
219 | $fetchedCaches = $qb->execute()->fetchAll(); |
||
220 | |||
221 | $array_size = count($fetchedCaches); |
||
222 | for ($i = 0; $i < $array_size; $i ++) { |
||
223 | // replace existing log passwords with something different |
||
224 | // nur der Teil mit den Bilderzuweisungen müsste nochmal überdacht werden.. |
||
225 | if ($fetchedCaches[$i]["logpw"] != "") { |
||
226 | $fetchedCaches[$i]["logpw"] = 1; |
||
227 | } else { |
||
228 | $fetchedCaches[$i]["logpw"] = 0; |
||
229 | } |
||
230 | |||
231 | // replace cache type information with picture links |
||
232 | // auch hier müsste die Bildzuweisung nochmal überarbeitet werden.. |
||
233 | $fetchedCaches[$i]["cache_type_picture"] = |
||
234 | "https://www.opencaching.de/resource2/ocstyle/images/cacheicon/" |
||
235 | . $fetchedCaches[$i]["cache_type_picture"]; |
||
236 | } |
||
237 | } |
||
238 | |||
239 | //dd($fetchedCaches); |
||
240 | //die(); |
||
241 | |||
242 | return $fetchedCaches; |
||
243 | } |
||
244 | } |
||
245 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.