We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 5 |
| Paths | 8 |
| Total Lines | 55 |
| Code Lines | 39 |
| 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 |
||
| 43 | public function getCollections($settings, $uid, $sysLangUid) { |
||
| 44 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 45 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
| 46 | |||
| 47 | $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0); |
||
| 48 | $orderBy = 'tx_dlf_collections.label'; |
||
| 49 | $showUserDefinedColls = ''; |
||
| 50 | // Handle collections set by configuration. |
||
| 51 | if ($settings['collections']) { |
||
| 52 | $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $settings['collections']))); |
||
| 53 | } |
||
| 54 | |||
| 55 | // Should user-defined collections be shown? |
||
| 56 | if (empty($settings['show_userdefined'])) { |
||
| 57 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 58 | } elseif ($settings['show_userdefined'] > 0) { |
||
| 59 | if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) { |
||
| 60 | $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($uid)); |
||
| 61 | } else { |
||
| 62 | $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | // Get collections. |
||
| 67 | $queryBuilder |
||
| 68 | ->select( |
||
| 69 | 'tx_dlf_collections.uid AS uid', // required by getRecordOverlay() |
||
| 70 | 'tx_dlf_collections.pid AS pid', // required by getRecordOverlay() |
||
| 71 | 'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay() |
||
| 72 | 'tx_dlf_collections.index_name AS index_name', |
||
| 73 | 'tx_dlf_collections.index_search as index_query', |
||
| 74 | 'tx_dlf_collections.label AS label', |
||
| 75 | 'tx_dlf_collections.thumbnail AS thumbnail', |
||
| 76 | 'tx_dlf_collections.description AS description', |
||
| 77 | 'tx_dlf_collections.priority AS priority' |
||
| 78 | ) |
||
| 79 | ->from('tx_dlf_collections') |
||
| 80 | ->where( |
||
| 81 | $selectedCollections, |
||
| 82 | $showUserDefinedColls, |
||
| 83 | $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])), |
||
| 84 | $queryBuilder->expr()->andX( |
||
| 85 | $queryBuilder->expr()->orX( |
||
| 86 | $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]), |
||
| 87 | $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $sysLangUid) |
||
| 88 | ), |
||
| 89 | $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0) |
||
| 90 | ) |
||
| 91 | ) |
||
| 92 | ->orderBy($orderBy); |
||
| 93 | |||
| 94 | $result = $queryBuilder->execute(); |
||
| 95 | $count = $queryBuilder->count('uid')->execute()->fetchColumn(0); |
||
| 96 | |||
| 97 | return ['result' => $result, 'count' => $count]; |
||
| 98 | } |
||
| 222 | } |