| Conditions | 23 |
| Paths | 208 |
| Total Lines | 90 |
| Code Lines | 57 |
| 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 |
||
| 49 | public function render($conf = []) |
||
| 50 | { |
||
| 51 | // Reset items and data |
||
| 52 | $this->itemArray = []; |
||
| 53 | $this->data = []; |
||
| 54 | |||
| 55 | $theValue = ''; |
||
| 56 | $originalRec = $GLOBALS['TSFE']->currentRecord; |
||
| 57 | // If the currentRecord is set, we register, that this record has invoked this function. |
||
| 58 | // It's should not be allowed to do this again then!! |
||
| 59 | if ($originalRec) { |
||
| 60 | ++$GLOBALS['TSFE']->recordRegister[$originalRec]; |
||
| 61 | } |
||
| 62 | |||
| 63 | $tables = $this->cObj->stdWrapValue('tables', $conf); |
||
| 64 | if ($tables) { |
||
| 65 | $tablesArray = array_unique(GeneralUtility::trimExplode(',', $tables, true)); |
||
| 66 | // Add tables which have a configuration (note that this may create duplicate entries) |
||
| 67 | if (is_array($conf['conf.'])) { |
||
| 68 | foreach ($conf['conf.'] as $key => $value) { |
||
| 69 | if (substr($key, -1) !== '.' && !in_array($key, $tablesArray)) { |
||
| 70 | $tablesArray[] = $key; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // Get the data, depending on collection method. |
||
| 76 | // Property "source" is considered more precise and thus takes precedence over "categories" |
||
| 77 | $source = $this->cObj->stdWrapValue('source', $conf); |
||
| 78 | $categories = $this->cObj->stdWrapValue('categories', $conf); |
||
| 79 | if ($source) { |
||
| 80 | $this->collectRecordsFromSource($source, $tablesArray); |
||
| 81 | } elseif ($categories) { |
||
| 82 | $relationField = $this->cObj->stdWrapValue('relation', $conf['categories.'] ?? []); |
||
| 83 | $this->collectRecordsFromCategories($categories, $tablesArray, $relationField); |
||
| 84 | } |
||
| 85 | $itemArrayCount = count($this->itemArray); |
||
| 86 | if ($itemArrayCount > 0) { |
||
| 87 | /** @var ContentObjectRenderer $cObj */ |
||
| 88 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
| 89 | $cObj->setParent($this->cObj->data, $this->cObj->currentRecord); |
||
| 90 | $this->cObj->currentRecordNumber = 0; |
||
| 91 | $this->cObj->currentRecordTotal = $itemArrayCount; |
||
| 92 | foreach ($this->itemArray as $val) { |
||
| 93 | $row = $this->data[$val['table']][$val['id']]; |
||
| 94 | // Perform overlays if necessary (records coming from category collections are already overlaid) |
||
| 95 | if ($source) { |
||
| 96 | // Versioning preview |
||
| 97 | $this->getPageRepository()->versionOL($val['table'], $row); |
||
| 98 | // Language overlay |
||
| 99 | if (is_array($row)) { |
||
| 100 | $row = $this->getPageRepository()->getLanguageOverlay($val['table'], $row); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | // Might be unset during the overlay process |
||
| 104 | if (is_array($row)) { |
||
| 105 | $dontCheckPid = $this->cObj->stdWrapValue('dontCheckPid', $conf); |
||
| 106 | if (!$dontCheckPid) { |
||
| 107 | $validPageId = $this->getPageRepository()->filterAccessiblePageIds([$row['pid']]); |
||
| 108 | $row = !empty($validPageId) ? $row : ''; |
||
| 109 | } |
||
| 110 | if ($row && !$GLOBALS['TSFE']->recordRegister[$val['table'] . ':' . $val['id']]) { |
||
| 111 | $renderObjName = $conf['conf.'][$val['table']] ?: '<' . $val['table']; |
||
| 112 | $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.' . $val['table'] : ''; |
||
| 113 | $renderObjConf = $conf['conf.'][$val['table'] . '.']; |
||
| 114 | $this->cObj->currentRecordNumber++; |
||
| 115 | $cObj->parentRecordNumber = $this->cObj->currentRecordNumber; |
||
| 116 | $GLOBALS['TSFE']->currentRecord = $val['table'] . ':' . $val['id']; |
||
| 117 | $this->cObj->lastChanged($row['tstamp']); |
||
| 118 | $cObj->start($row, $val['table']); |
||
|
|
|||
| 119 | $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey); |
||
| 120 | $theValue .= $tmpValue; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | $wrap = $this->cObj->stdWrapValue('wrap', $conf); |
||
| 127 | if ($wrap) { |
||
| 128 | $theValue = $this->cObj->wrap($theValue, $wrap); |
||
| 129 | } |
||
| 130 | if (isset($conf['stdWrap.'])) { |
||
| 131 | $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']); |
||
| 132 | } |
||
| 133 | // Restore |
||
| 134 | $GLOBALS['TSFE']->currentRecord = $originalRec; |
||
| 135 | if ($originalRec) { |
||
| 136 | --$GLOBALS['TSFE']->recordRegister[$originalRec]; |
||
| 137 | } |
||
| 138 | return $theValue; |
||
| 139 | } |
||
| 241 |