Passed
Branch master (6c65a4)
by Christian
16:31
created

ContentContentObject::render()   F

Complexity

Conditions 29
Paths > 20000

Size

Total Lines 100
Code Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 29
eloc 71
nc 1310721
nop 1
dl 0
loc 100
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
namespace TYPO3\CMS\Frontend\ContentObject;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
20
21
/**
22
 * Contains CONTENT class object.
23
 */
24
class ContentContentObject extends AbstractContentObject
25
{
26
    /**
27
     * Rendering the cObject, CONTENT
28
     *
29
     * @param array $conf Array of TypoScript properties
30
     * @return string Output
31
     */
32
    public function render($conf = [])
33
    {
34
        if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
35
            return '';
36
        }
37
38
        $frontendController = $this->getFrontendController();
39
        $theValue = '';
40
        $originalRec = $frontendController->currentRecord;
41
        // If the currentRecord is set, we register, that this record has invoked this function.
42
        // It's should not be allowed to do this again then!!
43
        if ($originalRec) {
44
            ++$frontendController->recordRegister[$originalRec];
45
        }
46
        $conf['table'] = isset($conf['table.']) ? trim($this->cObj->stdWrap($conf['table'], $conf['table.'])) : trim($conf['table']);
47
        $conf['select.'] = !empty($conf['select.']) ? $conf['select.'] : [];
48
        $renderObjName = $conf['renderObj'] ?: '<' . $conf['table'];
49
        $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
50
        $renderObjConf = $conf['renderObj.'];
51
        $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap($conf['slide'], $conf['slide.']) : (int)$conf['slide'];
0 ignored issues
show
Bug introduced by
It seems like $conf['slide'] can also be of type array; however, parameter $content of TYPO3\CMS\Frontend\Conte...jectRenderer::stdWrap() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap(/** @scrutinizer ignore-type */ $conf['slide'], $conf['slide.']) : (int)$conf['slide'];
Loading history...
Bug introduced by
It seems like $conf['slide.'] can also be of type string; however, parameter $conf of TYPO3\CMS\Frontend\Conte...jectRenderer::stdWrap() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $slide = isset($conf['slide.']) ? (int)$this->cObj->stdWrap($conf['slide'], /** @scrutinizer ignore-type */ $conf['slide.']) : (int)$conf['slide'];
Loading history...
52
        if (!$slide) {
53
            $slide = 0;
54
        }
55
        $slideCollect = isset($conf['slide.']['collect.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collect'], $conf['slide.']['collect.']) : (int)$conf['slide.']['collect'];
56
        if (!$slideCollect) {
57
            $slideCollect = 0;
58
        }
59
        $slideCollectReverse = isset($conf['slide.']['collectReverse.']) ? (int)$this->cObj->stdWrap($conf['slide.']['collectReverse'], $conf['slide.']['collectReverse.']) : (int)$conf['slide.']['collectReverse'];
60
        $slideCollectReverse = (bool)$slideCollectReverse;
61
        $slideCollectFuzzy = isset($conf['slide.']['collectFuzzy.'])
62
            ? (bool)$this->cObj->stdWrap($conf['slide.']['collectFuzzy'], $conf['slide.']['collectFuzzy.'])
63
            : (bool)$conf['slide.']['collectFuzzy'];
64
        if (!$slideCollect) {
65
            $slideCollectFuzzy = true;
66
        }
67
        $again = false;
68
        $tmpValue = '';
69
70
        do {
71
            $records = $this->cObj->getRecords($conf['table'], $conf['select.']);
72
            $cobjValue = '';
73
            if (!empty($records)) {
74
                $this->cObj->currentRecordTotal = count($records);
75
                $this->getTimeTracker()->setTSlogMessage('NUMROWS: ' . count($records));
76
77
                /** @var $cObj ContentObjectRenderer */
78
                $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
79
                $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
80
                $this->cObj->currentRecordNumber = 0;
81
82
                foreach ($records as $row) {
83
                    // Call hook for possible manipulation of database row for cObj->data
84
                    foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content_content.php']['modifyDBRow'] ?? [] as $className) {
85
                        $_procObj = GeneralUtility::makeInstance($className);
86
                        $_procObj->modifyDBRow($row, $conf['table']);
87
                    }
88
                    if (!$frontendController->recordRegister[$conf['table'] . ':' . $row['uid']]) {
89
                        $this->cObj->currentRecordNumber++;
90
                        $cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
91
                        $frontendController->currentRecord = $conf['table'] . ':' . $row['uid'];
92
                        $this->cObj->lastChanged($row['tstamp']);
93
                        $cObj->start($row, $conf['table']);
94
                        $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
0 ignored issues
show
Bug introduced by
It seems like $renderObjConf can also be of type string; however, parameter $conf of TYPO3\CMS\Frontend\Conte...nderer::cObjGetSingle() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
                        $tmpValue = $cObj->cObjGetSingle($renderObjName, /** @scrutinizer ignore-type */ $renderObjConf, $renderObjKey);
Loading history...
Bug introduced by
It seems like $renderObjName can also be of type array; however, parameter $name of TYPO3\CMS\Frontend\Conte...nderer::cObjGetSingle() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

94
                        $tmpValue = $cObj->cObjGetSingle(/** @scrutinizer ignore-type */ $renderObjName, $renderObjConf, $renderObjKey);
Loading history...
95
                        $cobjValue .= $tmpValue;
96
                    }
97
                }
98
            }
99
            if ($slideCollectReverse) {
100
                $theValue = $cobjValue . $theValue;
101
            } else {
102
                $theValue .= $cobjValue;
103
            }
104
            if ($slideCollect > 0) {
105
                $slideCollect--;
106
            }
107
            if ($slide) {
108
                if ($slide > 0) {
109
                    $slide--;
110
                }
111
                $conf['select.']['pidInList'] = $this->cObj->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
112
                if (isset($conf['select.']['pidInList.'])) {
113
                    unset($conf['select.']['pidInList.']);
114
                }
115
                $again = (string)$conf['select.']['pidInList'] !== '';
116
            }
117
        } while ($again && $slide && ((string)$tmpValue === '' && $slideCollectFuzzy || $slideCollect));
118
119
        $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
120
        if ($wrap) {
121
            $theValue = $this->cObj->wrap($theValue, $wrap);
122
        }
123
        if (isset($conf['stdWrap.'])) {
124
            $theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
125
        }
126
        // Restore
127
        $frontendController->currentRecord = $originalRec;
128
        if ($originalRec) {
129
            --$frontendController->recordRegister[$originalRec];
130
        }
131
        return $theValue;
132
    }
133
134
    /**
135
     * Returns the frontend controller
136
     *
137
     * @return TypoScriptFrontendController
138
     */
139
    protected function getFrontendController()
140
    {
141
        return $GLOBALS['TSFE'];
142
    }
143
144
    /**
145
     * Returns Time Tracker
146
     *
147
     * @return TimeTracker
148
     */
149
    protected function getTimeTracker()
150
    {
151
        return GeneralUtility::makeInstance(TimeTracker::class);
152
    }
153
}
154