[TASK] Cleanup unnecessary calls to reset() or current()
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 17 Jun 2011 22:36:55 +0000 (00:36 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 18 Jun 2011 14:46:18 +0000 (16:46 +0200)
Change-Id: I055760fdd1960dbfa8b574523c8b88ea84f619f8
Resolves: #27530
Reviewed-on: http://review.typo3.org/2792
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
20 files changed:
t3lib/class.t3lib_admin.php
t3lib/class.t3lib_befunc.php
t3lib/class.t3lib_clipboard.php
t3lib/class.t3lib_div.php
t3lib/class.t3lib_extmgm.php
t3lib/class.t3lib_fullsearch.php
t3lib/class.t3lib_parsehtml.php
t3lib/class.t3lib_tceforms_inline.php
t3lib/class.t3lib_tcemain.php
t3lib/class.t3lib_tsparser_ext.php
t3lib/utility/class.t3lib_utility_debug.php
typo3/alt_clickmenu.php
typo3/alt_doc.php
typo3/alt_shortcut.php
typo3/backend.php
typo3/class.alt_menu_functions.inc
typo3/class.browse_links.php
typo3/wizard_add.php
typo3/wizard_rte.php
typo3/wizard_table.php

index 40674e6..93a82c7 100644 (file)
@@ -473,7 +473,6 @@ class t3lib_admin {
         */
        function getDBFields($theSearchTable) {
                $result = array();
-               reset($GLOBALS['TCA']);
                foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                        t3lib_div::loadTCA($table);
                        $cols = $GLOBALS['TCA'][$table]['columns'];
index 71882b8..67db2fb 100644 (file)
@@ -3526,8 +3526,7 @@ final class t3lib_BEfunc {
                        foreach ($rootLine as $row) {
                                $dRec = self::getRecordsByField('sys_domain', 'pid', $row['uid'], ' AND redirectTo=\'\' AND hidden=0', '', 'sorting');
                                if (is_array($dRec)) {
-                                       reset($dRec);
-                                       $dRecord = current($dRec);
+                                       $dRecord = reset($dRec);
                                        return rtrim($dRecord['domainName'], '/');
                                }
                        }
index 2b3412f..4a775bb 100644 (file)
@@ -702,8 +702,7 @@ class t3lib_clipboard {
                        if ($table == '_FILE') {
                                $thisRecTitle = basename($rec);
                                if ($this->current == 'normal') {
-                                       reset($clElements);
-                                       $selItem = current($clElements);
+                                       $selItem = reset($clElements);
                                        $selRecTitle = basename($selItem);
                                } else {
                                        $selRecTitle = count($clElements);
index caae0b3..17505a9 100644 (file)
@@ -2049,7 +2049,6 @@ final class t3lib_div {
         * @return      string          A single line of CSV
         */
        public static function csvValues(array $row, $delim = ',', $quote = '"') {
-               reset($row);
                $out = array();
                foreach ($row as $value) {
                        $out[] = str_replace($quote, $quote . $quote, $value);
@@ -5929,4 +5928,4 @@ final class t3lib_div {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 565c654..d9b1b19 100644 (file)
@@ -1609,7 +1609,6 @@ $TYPO3_LOADED_EXT = unserialize(stripslashes(\'' . addslashes(serialize($extensi
 
                $out = 0;
                if (is_array($cacheFiles)) {
-                       reset($cacheFiles);
                        foreach ($cacheFiles as $cfile) {
                                @unlink($cfile);
                                clearstatcache();
index df35070..0c5af12 100644 (file)
@@ -965,8 +965,7 @@ class t3lib_fullsearch {
                                        $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label'];
                                        $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt'];
                                        if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) {
-                                               reset($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']);
-                                               while (list(, $labelArray) = each($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'])) {
+                                               foreach ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
                                                        if (substr($labelArray[0], 0, 4) == 'LLL:') {
                                                                $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
                                                        } else {
@@ -976,7 +975,6 @@ class t3lib_fullsearch {
                                                $useSelectLabels = 1;
                                        }
                                        if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) {
-                                               reset($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']);
                                                foreach ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
                                                        if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
                                                                $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
@@ -1017,7 +1015,6 @@ class t3lib_fullsearch {
                                                }
                                                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                                        }
-                                       reset($this->tableArray[$from_table]);
                                        foreach ($this->tableArray[$from_table] as $key => $val) {
                                                $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' :
                                                                $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'];
index f05e80f..82629c0 100644 (file)
@@ -1229,7 +1229,6 @@ class t3lib_parsehtml {
                $cacheKey .= $flag ? 1 : 0;
                if (is_array($str)) {
                        if (!$cacheKey || !isset($this->caseShift_cache[$cacheKey])) {
-                               reset($str);
                                foreach ($str as &$v) {
                                        if (!$flag) {
                                                $v = strtoupper($v);
index fe3bee0..bf1944f 100644 (file)
@@ -1688,8 +1688,7 @@ class t3lib_TCEforms_inline {
                $trData->disableRTE = $GLOBALS['SOBE']->MOD_SETTINGS['disableRTE'];
                        // if a new record should be created
                $trData->fetchRecord($table, $uid, ($cmd === 'new' ? 'new' : ''));
-               reset($trData->regTableItems_data);
-               $rec = current($trData->regTableItems_data);
+               $rec = reset($trData->regTableItems_data);
 
                return $rec;
        }
index 6075374..365d77d 100644 (file)
@@ -412,7 +412,6 @@ class t3lib_TCEmain {
                if (is_array($mirror)) {
                        foreach ($mirror as $table => $uid_array) {
                                if (isset($this->datamap[$table])) {
-                                       reset($uid_array);
                                        foreach ($uid_array as $id => $uidList) {
                                                if (isset($this->datamap[$table][$id])) {
                                                        $theIdsInArray = t3lib_div::trimExplode(',', $uidList, 1);
@@ -464,8 +463,7 @@ class t3lib_TCEmain {
                                return FALSE;
                        }
 
-                       reset($postFiles);
-                       $subA = current($postFiles);
+                       $subA = reset($postFiles);
                        if (is_array($subA)) {
                                if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
                                                // Initialize the uploadedFilesArray:
index 86c7127..5bf5792 100644 (file)
@@ -837,7 +837,6 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
         */
        function ext_compareFlatSetups($default) {
                $editableComments = array();
-               reset($this->flatSetup);
                foreach ($this->flatSetup as $const => $value) {
                        if (substr($const, -2) != '..' && isset($this->flatSetup[$const . '..'])) {
                                $comment = trim($this->flatSetup[$const . '..']);
@@ -1291,7 +1290,6 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                                                        if ($extList == 'IMAGE_EXT') {
                                                                $extList = $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'];
                                                        }
-                                                       reset($this->rArr);
                                                        $onlineResourceFlag = $this->ext_defaultOnlineResourceFlag;
 
                                                        foreach ($this->rArr as $c => $val) {
index 78738b8..d819f66 100644 (file)
@@ -241,8 +241,7 @@ final class t3lib_utility_Debug {
         */
        public static function debugRows($rows, $header = '', $returnHTML = FALSE) {
                if (is_array($rows)) {
-                       reset($rows);
-                       $firstEl = current($rows);
+                       $firstEl = reset($rows);
                        if (is_array($firstEl)) {
                                $headerColumns = array_keys($firstEl);
                                $tRows = array();
index 71de085..05daf80 100644 (file)
@@ -897,8 +897,7 @@ class clickMenu {
                        $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
                        if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path))       {
                                $elArr = $this->clipObj->elFromTable('_FILE');
-                               reset($elArr);
-                               $selItem = current($elArr);
+                               $selItem = reset($elArr);
                                $elInfo=array(
                                        basename($selItem),
                                        basename($path),
index 95b6077..3de031e 100644 (file)
@@ -727,8 +727,7 @@ class SC_alt_doc {
                                                                $trData->disableRTE = !$GLOBALS['BE_USER']->isRTE();
                                                                $trData->prevPageID = $prevPageID;
                                                                $trData->fetchRecord($table,$theUid,$cmd=='new'?'new':'');      // 'new'
-                                                               reset($trData->regTableItems_data);
-                                                               $rec = current($trData->regTableItems_data);
+                                                               $rec = reset($trData->regTableItems_data);
                                                                $rec['uid'] = $cmd=='new' ? uniqid('NEW') : $theUid;
                                                                if ($cmd=='new')        {
                                                                        $rec['pid'] = $theUid=='prev'?$thePrevUid:$theUid;
@@ -1457,8 +1456,7 @@ class SC_alt_doc {
                        if (isset($this->docHandler[$currentDocFromHandlerMD5]))        {
                                $setupArr=$this->docHandler[$currentDocFromHandlerMD5];
                        } else {
-                               reset($this->docHandler);
-                               $setupArr=current($this->docHandler);
+                               $setupArr = reset($this->docHandler);
                        }
                        if ($setupArr[2])       {
                                $sParts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
index af2363d..09a92bc 100644 (file)
@@ -598,8 +598,7 @@ class SC_alt_shortcut {
                                } else {
                                        $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
                                        if (is_array($records)) {
-                                               reset($records);
-                                               $this->theEditRec = current($records);
+                                               $this->theEditRec = reset($records);
                                                t3lib_BEfunc::workspaceOL('pages',$this->theEditRec);
                                        }
                                }
index 4aca26d..0840750 100644 (file)
@@ -641,8 +641,7 @@ class TYPO3backend {
                                $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
 
                                if(is_array($records))  {
-                                       reset($records);
-                                       $editRecord = current($records);
+                                       $editRecord = reset($records);
                                        t3lib_BEfunc::workspaceOL('pages', $editRecord);
                                }
                        }
index 076f388..680812c 100644 (file)
@@ -154,8 +154,7 @@ class alt_menu_functions {
                                if ($moduleInfo['defaultMod'])  {
                                        $link = $moduleInfo['sub'][$moduleInfo['defaultMod']]['script'];
                                } else {
-                                       reset($moduleInfo['sub']);
-                                       $subTemp = current($moduleInfo['sub']);
+                                       $subTemp = reset($moduleInfo['sub']);
                                        $link = $subTemp['script'];
                                }
                                $link_sub = 1;  // Tells that the main modules links to a submodule
index e51842d..070e939 100644 (file)
@@ -1254,8 +1254,10 @@ class browse_links {
                        $allowedItems = $hookObject->addAllowedItems($allowedItems);
                }
 
-               reset($allowedItems);
-               if (!in_array($this->act,$allowedItems))        $this->act = current($allowedItems);
+                       // if $this->act is not allowed, default to first allowed
+               if (!in_array($this->act, $allowedItems)) {
+                       $this->act = reset($allowedItems);
+               }
 
                        // Making menu in top:
                $menuDef = array();
index 3afcbe4..38ca8e0 100644 (file)
@@ -163,8 +163,7 @@ class SC_wizard_add {
                                        // Preparing the data of the parent record...:
                                $trData = t3lib_div::makeInstance('t3lib_transferData');
                                $trData->fetchRecord($this->P['table'],$this->P['uid'],'');     // 'new'
-                               reset($trData->regTableItems_data);
-                               $current = current($trData->regTableItems_data);
+                               $current = reset($trData->regTableItems_data);
 
                                        // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
                                if (is_array($current)) {
index 2765bb4..3b9d26e 100644 (file)
@@ -167,8 +167,7 @@ class SC_wizard_rte {
                        $trData->fetchRecord($this->P['table'],$this->P['uid'],'');
 
                                // Getting the processed record content out:
-                       reset($trData->regTableItems_data);
-                       $rec = current($trData->regTableItems_data);
+                       $rec = reset($trData->regTableItems_data);
                        $rec['uid'] = $this->P['uid'];
                        $rec['pid'] = $rawRec['pid'];
 
index 5c4fb95..a81e4e8 100644 (file)
@@ -402,8 +402,7 @@ class SC_wizard_table {
                $cells=array();
                $cells[]='';
                        // Finding first row:
-               reset($cfgArr);
-               $firstRow=current($cfgArr);
+               $firstRow = reset($cfgArr);
                if (is_array($firstRow))        {
 
                                // Init: