| Conditions | 14 |
| Paths | 401 |
| Total Lines | 79 |
| Code Lines | 47 |
| 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 |
||
| 53 | public function generateItems(): void |
||
| 54 | { |
||
| 55 | $table = $this->config['table']; |
||
| 56 | |||
| 57 | if (empty($table)) { |
||
| 58 | throw new MissingConfigurationException( |
||
| 59 | 'No configuration found for sitemap ' . $this->getKey(), |
||
| 60 | 1535576053 |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | |||
| 64 | $pids = !empty($this->config['pid']) ? GeneralUtility::intExplode(',', $this->config['pid']) : []; |
||
| 65 | $lastModifiedField = $this->config['lastModifiedField'] ?? 'tstamp'; |
||
| 66 | $sortField = $this->config['sortField'] ?? 'sorting'; |
||
| 67 | |||
| 68 | $changeFreqField = $this->config['changeFreqField'] ?? ''; |
||
| 69 | $priorityField = $this->config['priorityField'] ?? ''; |
||
| 70 | |||
| 71 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 72 | ->getQueryBuilderForTable($table); |
||
| 73 | |||
| 74 | $constraints = []; |
||
| 75 | if (!empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])) { |
||
| 76 | $constraints[] = $queryBuilder->expr()->in( |
||
| 77 | $GLOBALS['TCA'][$table]['ctrl']['languageField'], |
||
| 78 | [ |
||
| 79 | -1, // All languages |
||
| 80 | $this->getLanguageId() // Current language |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | |||
| 85 | if (!empty($pids)) { |
||
| 86 | $recursiveLevel = isset($this->config['recursive']) ? (int)$this->config['recursive'] : 0; |
||
| 87 | if ($recursiveLevel) { |
||
| 88 | $newList = []; |
||
| 89 | foreach ($pids as $pid) { |
||
| 90 | $list = $this->cObj->getTreeList($pid, $recursiveLevel); |
||
| 91 | if ($list) { |
||
| 92 | $newList = array_merge($newList, explode(',', $list)); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | $pids = array_merge($pids, $newList); |
||
| 96 | } |
||
| 97 | |||
| 98 | $constraints[] = $queryBuilder->expr()->in('pid', $pids); |
||
| 99 | } |
||
| 100 | |||
| 101 | if (!empty($this->config['additionalWhere'])) { |
||
| 102 | $constraints[] = QueryHelper::stripLogicalOperatorPrefix($this->config['additionalWhere']); |
||
| 103 | } |
||
| 104 | |||
| 105 | $queryBuilder->getRestrictions()->add( |
||
| 106 | GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getCurrentWorkspaceAspect()->getId()) |
||
| 107 | ); |
||
| 108 | |||
| 109 | $queryBuilder->select('*') |
||
| 110 | ->from($table); |
||
| 111 | |||
| 112 | if (!empty($constraints)) { |
||
| 113 | $queryBuilder->where( |
||
| 114 | ...$constraints |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | $rows = $queryBuilder->orderBy($sortField) |
||
| 119 | ->execute() |
||
| 120 | ->fetchAll(); |
||
| 121 | |||
| 122 | foreach ($rows as $row) { |
||
| 123 | $item = [ |
||
| 124 | 'data' => $row, |
||
| 125 | 'lastMod' => (int)$row[$lastModifiedField] |
||
| 126 | ]; |
||
| 127 | if (!empty($changeFreqField)) { |
||
| 128 | $item['changefreq'] = $row[$changeFreqField]; |
||
| 129 | } |
||
| 130 | $item['priority'] = !empty($priorityField) ? $row[$priorityField] : 0.5; |
||
| 131 | $this->items[] = $item; |
||
| 132 | } |
||
| 218 |