Conditions | 11 |
Paths | 160 |
Total Lines | 62 |
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 |
||
38 | public function generateItems(): void |
||
39 | { |
||
40 | $table = 'tx_calendarize_domain_model_index'; |
||
41 | |||
42 | $pids = !empty($this->config['pid']) ? GeneralUtility::intExplode(',', $this->config['pid']) : []; |
||
43 | $lastModifiedField = $this->config['lastModifiedField'] ?? 'tstamp'; |
||
44 | $sortField = $this->config['sortField'] ?? 'uid'; |
||
45 | |||
46 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
47 | ->getQueryBuilderForTable($table); |
||
48 | |||
49 | $constraints = []; |
||
50 | if (!empty($GLOBALS['TCA'][$table]['ctrl']['languageField'])) { |
||
51 | $constraints[] = $queryBuilder->expr()->in( |
||
52 | $GLOBALS['TCA'][$table]['ctrl']['languageField'], |
||
53 | [ |
||
54 | -1, // All languages |
||
55 | $this->getLanguageId(), // Current language |
||
56 | ] |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | if (!empty($pids)) { |
||
61 | $recursiveLevel = isset($this->config['recursive']) ? (int) $this->config['recursive'] : 0; |
||
62 | if ($recursiveLevel) { |
||
63 | $newList = []; |
||
64 | foreach ($pids as $pid) { |
||
65 | $list = $this->cObj->getTreeList($pid, $recursiveLevel); |
||
66 | if ($list) { |
||
67 | $newList = \array_merge($newList, \explode(',', $list)); |
||
68 | } |
||
69 | } |
||
70 | $pids = \array_merge($pids, $newList); |
||
71 | } |
||
72 | |||
73 | $constraints[] = $queryBuilder->expr()->in('pid', $pids); |
||
74 | } |
||
75 | |||
76 | if (!empty($this->config['additionalWhere'])) { |
||
77 | $constraints[] = $this->config['additionalWhere']; |
||
78 | } |
||
79 | |||
80 | $queryBuilder->select('*') |
||
81 | ->from($table); |
||
82 | |||
83 | if (!empty($constraints)) { |
||
84 | $queryBuilder->where( |
||
85 | ...$constraints |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | $rows = $queryBuilder->orderBy($sortField) |
||
90 | ->execute() |
||
91 | ->fetchAll(); |
||
92 | |||
93 | foreach ($rows as $row) { |
||
94 | $this->items[] = [ |
||
95 | 'data' => $row, |
||
96 | 'lastMod' => (int) $row[$lastModifiedField], |
||
97 | ]; |
||
98 | } |
||
99 | } |
||
100 | |||
186 |